我有一个Jenkinsfile(多分支管道),每当有人向Jenkins的任何分支提交内容时,它都会运行。
我的想法是它触发构建,每次测试通过时,它都会用新标记标记git存储库和docker镜像。
目前,每个构建都会构建一个名为application:latest的Docker镜像。在Git存储库和Docker镜像中实现一些标记系统会很不错。
所以我的Github repo有0.0.1,0.0.2,0.0.3作为标签。并且Docker镜像也作为应用程序推送:0.0.1到Docker中心。然后最新的标记构建,不应该只被称为应用程序:0.0.3,而且应用程序:最新。
我是如何在Github中用Jenkins实现这样一个系统的?
这是我目前的Jenkins文件:
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
*/
}
}
}
}
你在使用maven还是gradle?因为我有同样的问题,我通过添加一个从模板生成dockerfile的脚本来修复版本uppgrad。你可以check my github project for the groovy script