How do I tag the current git changeset from inside the Jenkinsfile?

前端 未结 4 840
时光取名叫无心
时光取名叫无心 2020-12-30 09:09

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.

I want to use this logic in orde

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 09:49

    To get this working for blue ocean (which uses https connection) use the following:

    sshagent(credentials: ["406ef572-9598-45ee-8d39-9c9a227a9227"]) {
                    def repository = "git@" + env.GIT_URL.replaceFirst(".+://", "").replaceFirst("/", ":")
                    sh("git remote set-url origin $repository")
                    sh("git tag --force build-${env.BRANCH_NAME}")
                    sh("git push --force origin build-${env.BRANCH_NAME}")
                }
    

提交回复
热议问题