简体   繁体   English

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

[英]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.

相关问题 如何在 Jenkins Multibranch Pipeline 中参数化 Git URL? - How to parameterize Git URL in Jenkins Multibranch Pipeline? 如何在 git push 上将自定义参数传递给 jenkins 作业(多分支管道)? - How to pass custom parameters to jenkins job (multibranch pipeline) on git push? Jenkins 多分支管道:如何获取最新的 git 标签? - Jenkins multibranch pipeline: how to get most recent git tag? Jenkins 多分支管道 git 配置错误 - Jenkins MultiBranch Pipeline git config error Jenkins多分支管道中的Git commit和push问题 - Git commit and push issue in Jenkins multibranch pipeline 如何触发对 jenkins 多分支管道的扫描? - How do I trigger a scan for a jenkins multibranch pipeline? 使用 jenkins 管道脚本标记 git repo - Tagging a git repo using jenkins pipeline script Jenkins MultiBranch-从管道文件(Jenkinsfile)参考git repo的标签 - Jenkins MultiBranch - Reference git repo's tag from pipeline file (Jenkinsfile) 如何在Jenkins管道或Multibranch管道中获取SCM URL? - How do I get the SCM URL inside a Jenkins Pipeline or Multibranch Pipeline? 如何在 jenkins 多分支脚本管道中获取最新的 git 提交作者姓名或消息并在分支条件下使用 - How to get latest git commit author name or message in jenkins multibranch scripted pipeline and use under branch condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM