Skip to content

Instantly share code, notes, and snippets.

@rlespinasse
Last active September 26, 2019 11:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rlespinasse/bf74dc19ada8b4877a5b to your computer and use it in GitHub Desktop.
Save rlespinasse/bf74dc19ada8b4877a5b to your computer and use it in GitHub Desktop.
Jenkinsfile to tag the sources used by current build
node {
repositoryAccess = 'https://'
repositoryAccessSeparator = '/'
echo "repository host: ${repositoryHost}" // github.com
echo "repository path: ${repositoryPath}" // <user>/<repository>.git
echo "repository jenkins credentials id: ${credentialsId}" // jenkins credentials for the jenkins git account who have commit access
echo "repository branch: ${branch}" // master or another branch
echo "repository commiter username: ${repositoryCommiterUsername}" // Jenkins account email
echo "repository commiter name: ${repositoryCommiterEmail}" // Jenkins
repositoryUrl = "${repositoryHost}${repositoryAccessSeparator}${repositoryPath}"
repositoryUrlFull = "${repositoryAccess}${repositoryUrl}"
echo "repository url: ${repositoryUrl}" // github.com/<user>/<repository>.git
echo "repository url full: ${repositoryUrlFull}" // https://github.com/<user>/<repository>.git
echo "download sources from repository branch"
git credentialsId: credentialsId, url: repositoryUrlFull, branch: branch
echo "tag the sources with this build tag and push the tag to origin repository"
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: credentialsId,
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD']]) {
sh("git config user.email ${repositoryCommiterEmail}")
sh("git config user.name '${repositoryCommiterUsername}'")
sh("git tag -a ${env.BUILD_TAG} -m '${repositoryCommiterMessage}'")
sh("git push ${repositoryAccess}${env.GIT_USERNAME}:${env.GIT_PASSWORD}@${repositoryUrl} --tags")
}
}
@ssbarnea
Copy link

ssbarnea commented Apr 1, 2016

Can you please tell me how do you get these variables loaded. On my instance it complains that repositoryPath is not defined. Is there a place where can I find these? My jobs are all generated by the github-organization-plugin. Thank!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment