【发布时间】:2022-01-20 14:10:55
【问题描述】:
我正在开发一个 CI/DC 管道,其中有一个 DEV、TEST 和 Prod 服务器。使用 Jenkins 流水线,我将最新的图像部署到我的 DEV-Server 上。现在我想通过读出 sha256 id 来获取我的 DEV-Server 的图像并将其放在我的 TEST-Server 上。
为此我有一个 Jenkins 流水线:
pipeline {
agent any
tools {
dockerTool 'docker-19.03.9'
}
environment {
}
stages {
stage('DeployToTEST-Angular') {
steps {
script {
echo 'Deploying image...'
sh 'docker stop mycontainertest'
sh 'docker rm mycontainertest'
sh 'docker run -d --name mycontainertest [cant show the envirmoments i give with] --restart always angular:latest'
}
}
}
}
如你所见,我目前使用 :latest 标签,但我想要这样的:
pipeline {
agent any
tools {
dockerTool 'docker-19.03.9'
}
environment {
}
stages {
stage('DeployToTEST-Angular') {
steps {
script {
echo 'Deploying image...'
sh 'docker stop mycontainertest'
sh 'docker rm mycontainertest'
sh 'docker run -d --name mycontainertest [cant show the envirmoments i give with] --restart always \$imageofDev'
}
}
}
}
$imageofDev = docker 检查 mycontainerdev | grep -o 'sha256:[^"]*' // 此命令有效并返回原始 sha256 编号
以便它使用我的开发图像的实际 sha256 编号
我不知道如何定义这个变量,然后在这个 Jenkins 管道中使用它的值。我该怎么做?
【问题讨论】: