Skip to content

Instantly share code, notes, and snippets.

@mrhockeymonkey
Last active March 18, 2024 13:38
Show Gist options
  • Save mrhockeymonkey/ecb0cb5cb4ed55e64a4bc231f93efe58 to your computer and use it in GitHub Desktop.
Save mrhockeymonkey/ecb0cb5cb4ed55e64a4bc231f93efe58 to your computer and use it in GitHub Desktop.
#!groovy
pipeline {
agent any
stages {
stage ("check") {
when {
branch 'master'
}
steps {
withCredentials([usernamePassword(credentialsId: 'scm-account', passwordVariable: 'SCMPASS', usernameVariable: 'SCMUSER')]) {
// fetch information about tags
sh "git config --add remote.origin.fetch +refs/heads/master:refs/remotes/origin/master"
sh "git fetch https://${SCMUSER}:${SCMPASS}@git.contoso.com/ORG/REPO.git"
// Use git log to build a list of changes from th elast tag to current master
sh """
lastRelease=\$(git describe --tags --abbrev=0 origin/master)
git log --format=format:\"%s (%an)\" \${lastRelease}..origin/master > gitlog
if [ -s gitlog ]
then
echo yes > haschanges
else
echo no > haschanges
echo No release required, No commits found since \$lastRelease
fi
"""
script {
env.HAS_CHANGES = readFile('haschanges').trim()
}
}
}
}
stage ("release") {
when {
environment name: 'HAS_CHANGES', value: 'yes'
}
steps {
withCredentials([usernamePassword(credentialsId: 'scm-account', passwordVariable: 'SCMPASS', usernameVariable: 'SCMUSER')]) {
sh "python .jenkins/github-release.py -c -u $SCMUSER -p $SCMPASS -o mrhockeymonkey -r somerepo --description_file gitlog"
}
}
}
}
post {
cleanup {
deleteDir()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment