如何从Jenkinsfile中标记当前的git变更集?

sor*_*rin 9 jenkins jenkins-workflow jenkins-pipeline jenkinsfile

我想标记当前的git变更集并从Jenkins文件中推送标记.如果标签已存在,则必须更换.

我想使用这个逻辑来标记与snapshot标记一起传递的构建,这将是一个移动标记.

我怎样才能做到这一点?

sor*_*rin 12

这是我能够以这种方式实现这一点的方式,但如果你知道更好的方式,我更愿意听到它.

#!groovy

stage 'build'
node {

    repositoryCommiterEmail = 'ci@example.com'
    repositoryCommiterUsername = 'examle.com'

    checkout scm

    sh "echo done"

    if (env.BRANCH_NAME == 'master') {
        stage 'tagging'

        sh("git config user.email ${repositoryCommiterEmail}")
        sh("git config user.name '${repositoryCommiterUsername}'")

        sh "git remote set-url origin git@github.com:..."

        // deletes current snapshot tag
        sh "git tag -d snapshot || true"
        // tags current changeset
        sh "git tag -a snapshot -m \"passed CI\""
        // deletes tag on remote in order not to fail pushing the new one
        sh "git push origin :refs/tags/snapshot"
        // pushes the tags
        sh "git push --tags"
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这是有趣的.你如何对遥控器进行身份验证(如何发送密码)? (4认同)