[英]How to do Git & Docker tagging from a Jenkins multibranch pipeline
I have a Jenkinsfile (multi-branch pipeline) that's supposed to run every time somebody commits something to any branch in Jenkins. 我有一个Jenkinsfile(多分支管道),每当有人向Jenkins中的任何分支提交内容时,该文件都应该运行。
My idea is that it triggers a build and every time the tests pass, it will tag the git repository and docker image with a new tag. 我的想法是,它会触发构建,并且每当测试通过时,它将使用新标签标记git存储库和docker映像。
Currently every build, builds a Docker image called application:latest. 当前,每个构建都会构建一个名为application:latest的Docker映像。 It would be nice to implement some tagging system in both the Git repository and the Docker images.
最好在Git存储库和Docker映像中都实现一些标记系统。
So that my Github repo has 0.0.1, 0.0.2, 0.0.3 as tags. 这样我的Github存储库就有0.0.1、0.0.2、0.0.3作为标签。 And that the Docker image is also pushed as application:0.0.1 to the Docker hub.
而且Docker映像也作为application:0.0.1被推送到Docker中心。 Then also the latest tagged build, should not just be called application:0.0.3, but also application:latest.
然后,最新的带标记的版本不仅应被称为application:0.0.3,而且应被称为application:latest。
Any ideas how I can implement such a system with Jenkins in Github? 有什么想法可以在Github中使用Jenkins实施这样的系统吗?
This is my current Jenkinsfile: 这是我当前的Jenkinsfile:
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
}
environment {
DOCKER_CREDS = credentials('dockeruser-dockerhub-password')
}
stages {
stage('Git clone') {
/*
This is needed for local development, because Jenkins uses locally pasted pipeline code in a textarea box and doesn't know where the Git repo is.
This also means we have no multibranch, but that's no problem for local development.
*/
steps {
git url: 'https://github.com/gituser/denpal', branch: 'feature/Jenkinsfile'
}
}
stage('Docker login') {
steps {
sh """
docker login --username dockeruser --password $DOCKER_CREDS
"""
}
}
stage('Docker-compose') {
steps {
sh '''
docker-compose config -q
COMPOSE_PROJECT_NAME=denpal docker-compose down
COMPOSE_PROJECT_NAME=denpal docker-compose up -d --build "$@"
'''
}
}
stage('Docker push images') {
steps {
sh """
docker tag denpal:latest dockername/denpal:latest
docker push dockername/denpal:latest
docker tag denpal_nginx:latest dockername/denpal_nginx:latest
docker push dockername/denpal_nginx:latest
docker tag denpal_php:latest dockername/denpal_php:latest
docker push dockername/denpal_php:latest
"""
}
}
stage('Verification tests') {
steps {
sh """
docker-compose exec -T cli drush status
"""
/*
make this work, syntax error, """-issue?
if [ $? -eq 0 ]; then
echo "OK!"
else
echo "FAIL"
fi
*/
}
}
}
}
are you using maven or gradle ? 您正在使用Maven或Gradle吗? because i had the same problem and i fixed the version uppgrad by adding a script that generates the dockerfile from a template.
因为我有同样的问题,并且我通过添加从模板生成dockerfile的脚本来修复了uppgrad版本。 you can check my github project for the groovy script
您可以检查我的github项目中的groovy脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.