Skip to content

Instantly share code, notes, and snippets.

@frekele
Forked from rlespinasse/Jenkinsfile.groovy
Created July 19, 2016 03:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save frekele/847c8a5f458d5c84f5688975c8553848 to your computer and use it in GitHub Desktop.
Save frekele/847c8a5f458d5c84f5688975c8553848 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")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment