Tag a Repo from a Jenkins Workflow Script

后端 未结 5 614
孤城傲影
孤城傲影 2020-12-15 22:08

I\'m currently trying to tag a repo from a Jenkins Workflow script. I\'ve tried using a sh step but this runs into problems because of credentials not being set

5条回答
  •  悲哀的现实
    2020-12-15 22:33

    So I tried the solution of @user3617723 but from some reason something was missing. after a while I found my issue. I have an upper job which responsible to pull the git repo and trigger the pipeline job with my workflow script which has different workspace:

    //use the jenkins global credential id and create the env parametrs of GIT_PASSWORD and GIT_PASSWORD
    withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'cred-github', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
    
    //change directory to the work dir with the ".git" files and create tags
    sh("cd ${MANAGER_WORKSPACE} ; git tag -a v-${props.'VERSION_NUMBER'} -m ${BUILD_URL}")
    
    //get only the url after the https
    giturl_push = GIT_URL.split("//")[1]
    
    // change directory to the work dir with the ".git" files and push the tags to the repo
    sh("cd ${MANAGER_WORKSPACE} ; git push https://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@${giturl_push} --tags")
    
    
    
    
    }
    

提交回复
热议问题