gpt4 book ai didi

git - 如何从Jenkins多分支管道进行Git和Docker标记

转载 作者:行者123 更新时间:2023-12-02 18:07:22 26 4
gpt4 key购买 nike

我有一个Jenkinsfile(多分支管道),每当有人向Jenkins中的任何分支提交内容时,该文件都应该运行。

我的想法是,它触发构建,并且每当测试通过时,它将使用新标签标记git存储库和docker镜像。

当前,每个构建都会构建一个名为application:latest的Docker镜像。最好在Git存储库和Docker镜像中都实现一些标记系统。

这样我的Github存储库就有0.0.1、0.0.2、0.0.3作为标签。而且Docker镜像也作为application:0.0.1被推送到Docker中心。
然后,最新的带标签的构建不仅应被称为application:0.0.3,而且应被称为application:latest。

有什么想法可以在Github中使用Jenkins实现这样的系统吗?

这是我当前的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
*/
}
}
}
}

最佳答案

您正在使用Maven或Gradle吗?因为我有同样的问题,并且我通过添加从模板生成dockerfile的脚本来修复了uppgrad版本。
你可以check my github project for the groovy script

关于git - 如何从Jenkins多分支管道进行Git和Docker标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55470989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com