如何从Jenkinsfile内部标记当前的git changeset? [英] How do I tag the current git changeset from inside the Jenkinsfile?

查看:328
本文介绍了如何从Jenkinsfile内部标记当前的git changeset?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想标记当前的git changeset并从Jenkinsfile内部推送标记.如果标签已经存在,则必须将其替换.

I want to tag the current git changeset and push the tag from inside the Jenkinsfile. If the tag already exists it must be replaced.

我想使用此逻辑来标记通过snapshot标记传递的内部版本,该标记将是移动标记.

I want to use this logic in order to tag the build that passed with the snapshot tag, which would be a mobile tag.

我该怎么做?

推荐答案

这是我能够以这种方式实现的方法,但是,如果您知道更好的方法,那么我很乐意听到.

Here is the way I was able to implement this this way, but if you know a better way I am more than willing to hear it.

#!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"
    }
}

这篇关于如何从Jenkinsfile内部标记当前的git changeset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆