最新消息:时间抓起来说是金子,抓不住就是流水。

pipeline自动打标签

Jenkins 老子黑牵翻 2709浏览 0评论

生产在进行项目发布成功后,需要多当前代码在git上打个标签,已确保以后回滚或是需要用对应版本代码基础上继续开发使用,具体代码如下:

pipeline {
    agent any
    options{
        timeout(8) 
    }
    environment{
        git="项目git地址,前面不能带http://或是https://"
        GIT_TAG = sh(script: "echo `date '+%Y%m%d%H%M%S'`", returnStdout: true).trim()
    }
    
    stages {
        stage('清理工作空间'){steps {cleanWs()}}
        stage('代码下载') {
            steps {
                checkout([$class: 'GitSCM', 
                          branches: [[name: "master"]], 
                          doGenerateSubmoduleConfigurations: false, 
                          extensions: [], 
                          gitTool: 'Default', 
                          submoduleCfg: [], 
                          userRemoteConfigs: [[credentialsId: 'jenkins中Credentials信息', url: "http://${git}",]]
                        ])
            }
        }
            
        stage('编译打包'){
            steps {
		sh "${tools} clean package -Dmaven.test.skip=true"
        }
        
        stage('版本标签') {
            steps {
                withCredentials([usernamePassword(credentialsId: "jenkins中Credentials信息", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
                    sh """
                        git config --global user.email "test@test.com"
                        git config --global user.name "test"
                        git tag -a ${GIT_TAG} -m 'test'
                        git push http://${GIT_USERNAME}:${GIT_PASSWORD}@${git} --tags
                    """
                }
            }
        }
    }
}

转载请注明:LINUX服务器运维架构技术分享 » pipeline自动打标签

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址