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

前端 未结 4 819
时光取名叫无心
时光取名叫无心 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条回答
  •  萌比男神i
    2020-12-30 09:56

    I want to share my Jenkins Pipeline Setup and my solution to publish changes/tags to git repo via SSH (While Git Publish Support is under development). Please check it out for more info, any improvement ideas are welcome.

    In short you just add file git_push_ssh.groovy to your project and call method pushSSH() from Jenkinsfile like this:

    env.BRANCH_NAME = "mycoolbranch"// BRANCH_NAME is predefined in multibranch pipeline job
    env.J_GIT_CONFIG = "true"
    env.J_USERNAME = "Jenkins CI"
    env.J_EMAIL = "jenkins-ci@example.com"
    env.J_CREDS_IDS = '02aa92ec-593e-4a90-ac85-3f43a06cfae3' // Use credentials id from Jenkins
    def gitLib = load "git_push_ssh.groovy"
    ...
    gitLib.pushSSH(commitMsg: "Jenkins build #${env.BUILD_NUMBER}", tagName: "build-${env.BUILD_NUMBER}", files: "changelog.txt someotherfile.txt");
    

提交回复
热议问题