jenkins pipeline打tag

以下四种方式皆可用
jenkins设置系统凭据
方式一:
pipeline {
agent any
stages {
stage(‘test’) {
steps {
git credentialsId: ‘凭据id’, url:“http://git.name:git.password@git地址 "
script{
def GIT_TAG = new Date().format(“yyyyMMddHHmmss”);
sh “””
git config user.email “your.email”
git config user.name “your.name”
git tag -a -m “${GIT_TAG}” ${GIT_TAG}
git push origin --tags
“”"
}
}

}

}
}

方式二:
Jenkins设置全局变量a=git.name, b=git.password
pipeline {
agent any
stages {
stage(‘test’) {
steps {
git credentialsId: ‘凭据id’, url:“http:// a : a: a:b@git地址 "
script{
def GIT_TAG = new Date().format(“yyyyMMddHHmmss”);
sh “””
git config user.email “your.email”
git config user.name “your.name”
git tag -a -m “${GIT_TAG}” ${GIT_TAG}
git push origin --tags
“”"
}
}

}

}
}
方式三:
Jenkins设置凭据
pipeline {
agent any
options {
timeout(time:600, unit: ‘SECONDS’)
buildDiscarder(logRotator(numToKeepStr: ‘7’))
timestamps()
}

stages {
stage(‘test’) {
steps {
git credentialsId: ‘凭据id’, url: "git地址 "
withCredentials([[$class: ‘UsernamePasswordMultiBinding’, credentialsId: ‘凭据id’, usernameVariable: ‘GIT_USERNAME’, passwordVariable: ‘GIT_PASSWORD’]]) {
script{
def GIT_TAG = new Date().format(“yyyyMMddHHmmss”);
sh(“git config credential.username ${env.GIT_USERNAME}”)
sh(“git config credential.helper ‘!echo password=$GIT_PASSWORD; echo’”)
sh("git tag -a -m ‘${GIT_TAG}’ ${GIT_TAG} ")
sh(“git remote add origin git地址 || git push origin --tags”)

}
}
}

}

}
}
方式四:(ssh)
jenkins配置ssh凭据
pipeline {
agent any
environment {
target_branch = ‘master’
target_repo_url = ‘ssh地址’

    git_auth_id = '凭据id'
   

  }

stages {
stage(‘Hello’) {
steps {

                 // Pull code
   
            script{
                   def GIT_TAG = new Date().format("yyyyMMddHHmmss");
                    git branch: env.target_branch, credentialsId: env.git_auth_id, url: env.target_repo_url
                sh("git tag -a ${GIT_TAG} -m 'Jenkins'")
                 sh("git push origin ${GIT_TAG}  --tags")
            }
     }
  }

}
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值