我是Jenkins的新手。今天我試圖創建一個Multibranche Pipeline。 我想用分支名稱標記創建的碼頭圖像。在Jenkins中不能使用env變量Pipeline/Multi-Pipeline
我詹金斯文件鎖喜歡如下:
node {
def app
stage('Clone repository') {
/* Let's make sure we have the repository cloned to our workspace */
checkout scm
}
stage('Build image') {
/* This builds the actual image; synonymous to
* docker build on the command line */
app = docker.build("brosftw/minecraft")
}
stage('Test image') {
app.inside {
sh 'echo ${BUILD_BRANCHENAME}'
}
}
stage('Push image') {
/* Finally, we'll push the image with two tags:
* First, the incremental build number from Jenkins
* Second, the 'latest' tag.
* Pushing multiple tags is cheap, as all the layers are reused. */
/* Docker credentials from Jenkins ID for BrosFTW Repository */
docker.withRegistry('https://registry.hub.docker.com', 'e2fd9e87-21a4-4ee0-86d4-da0f7949a984') {
/* If Branch is master tag it with the latest tag */
if ("${env.BUILD_BRANCHENAME}" == "master") {
app.push("latest")
} else {
/* If it is a normal branch tag it with the branch name */
app.push("${env.BUILD_BRANCHENAME}")
}
}
}
}
編輯從詹金斯作業日誌
泊塢窗推送請求:
+ docker tag brosftw/minecraft registry.hub.docker.com/brosftw/minecraft:null
[Pipeline] sh
[Minecraft-Test_master-ATFJUB2KKWARM4FFRXV2PEMHX6QFD24UQ5NGQXBIWT5YQJNXBAIA] Running shell script
+ docker push registry.hub.docker.com/brosftw/minecraft:null
The push refers to a repository [registry.hub.docker.com/brosftw/minecraft]
而且echo命令的輸出如下:
[Pipeline] {
[Pipeline] sh
[Minecraft-Test_master-ATFJUB2KKWARM4FFRXV2PEMHX6QFD24UQ5NGQXBIWT5YQJNXBAIA] Running shell script
+
[Pipeline]
任何人都可以告訴我我在做什麼錯了env變量?
我的第二個問題是,app.inside
不返回分支名稱....我不明白爲什麼。
感謝您的每一個答案。
實際上你的問題是什麼?什麼_not_工作? – StephenKing