Skip to content

Instantly share code, notes, and snippets.

@ryanmoon
Created October 15, 2020 19:24
Show Gist options
  • Save ryanmoon/d2fb892338f34f10b3aaad12be82759a to your computer and use it in GitHub Desktop.
Save ryanmoon/d2fb892338f34f10b3aaad12be82759a to your computer and use it in GitHub Desktop.
Pipeline Example where when using the Jenkins GitHub checks plugin, it stops communicating properly after multiple commits.
/* groovylint-disable DuplicateMapLiteral */
def call() {
pipeline {
triggers {
issueCommentTrigger('/redo_jenkins')
}
agent { label 'chef' }
environment {
CHEF_LICENSE = 'accept-silent'
DANGER_GITHUB_API_TOKEN = credentials('example')
GITHUB_RELEASE_AND_TAG_API_TOKEN = credentials('example2')
PATH = "/usr/local/bin:/usr/local/sbin:/usr/local/munki:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin:${env.PATH}"
}
options {
buildDiscarder(logRotator(daysToKeepStr: '2', numToKeepStr: '10', artifactNumToKeepStr: '10'))
}
stages {
stage(' 🦖 ') {
// ##########
// # PREPREP
// ##########
when {
// ################################
// # IF CHANGE_ID EXISTS = ON A PR
// ################################
allOf {
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
options {
timeout(time: 2, unit: "MINUTES")
}
steps {
echo 'PRE-PREP'
sh 'printenv'
}
}
stage(' 🏋🏻‍♀️ ') {
// ############
// # CHANGELOG
// ############
agent { node 'master' }
when {
// ################################
// # IF CHANGE_ID EXISTS = ON A PR
// ################################
allOf {
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
options {
timeout(time: 1, unit: "MINUTES")
}
steps {
echo 'CHANGELOG CHECK'
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
script {
// ########################
// # USE OUR DOCKER SERVER
// ########################
docker.withRegistry('https://example.docker.io', 'example_docker_login') {
sh 'docker run -v $PWD:/action -e GITHUB_RELEASE_AND_TAG_API_TOKEN="${GITHUB_RELEASE_AND_TAG_API_TOKEN}" example.docker.io/changelog_check_docker'
}
}
}
}
post {
always {
// ###############
// # TEST RESULTS
// ###############
junit 'changelog_check_results.xml'
recordIssues enabledForFailure: true, tool: junitParser(id: 'changelog', name: 'ChangeLogCheck', pattern: 'changelog_check_results.xml'), healthy: 2, unhealthy: 5, sourceCodeEncoding: 'UTF-8', forensicsDisabled: false
}
}
}
stage(' 🚨 ') {
// #########
// # DANGER
// #########
agent { node 'master' }
when {
// ################################
// # IF CHANGE_ID EXISTS = ON A PR
// ################################
anyOf {
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
options {
timeout(time: 2, unit: "MINUTES")
}
steps {
echo "DANGER - Helpful so we don't forget things."
script {
// ########################
// # USE OUR DOCKER SERVER
// ########################
docker.withRegistry('https://example.docker.io', 'example_docker_login') {
env.GIF = sh(script:'docker run example.docker.io/caller_on_the_line', returnStdout: true).trim()
sh 'docker run -v $PWD:/action -e DANGER_GITHUB_API_TOKEN="${DANGER_GITHUB_API_TOKEN}" -e CHANGE_ID="${CHANGE_ID}" -e CHANGE_URL="${CHANGE_URL}" -e JENKINS_URL="${JENKINS_URL}" -e GIF="${GIF}" example.docker.io/danger_docker'
}
}
}
}
stage(' ⛈ ') {
// ####################################
// # UPLOAD IF ON MASTER AND IF TAGGED
// ####################################
agent { node 'master' }
when { branch 'master' }
options {
timeout(time: 2, unit: "MINUTES")
}
steps {
echo 'Tag + Release + Upload'
script {
// ########################
// # USE OUR DOCKER SERVER
// ########################
docker.withRegistry('https://example.docker.io', 'example_docker_login') {
sh 'docker run -v $PWD:/action -e GITHUB_RELEASE_AND_TAG_API_TOKEN="${GITHUB_RELEASE_AND_TAG_API_TOKEN}" example.docker.io/github_tag_and_release_docker'
}
}
}
post {
failure {
// #########################
// # FOR FAILURE TELL SLACK
// #########################
slackSend (color:'RED', message: "Something in the tag / release process went awry. || ${buildStatus} || :whopper: || :plz-tag: '${env.JOB_NAME} || :buildy_spin: ${env.BUILD_NUMBER} || (${env.BUILD_URL})" )
}
}
}
}
post {
always {
deleteDir()
}
failure {
// #########################
// # FOR FAILURE TELL SLACK
// #########################
slackSend (color: 'RED', message: "${buildStatus} || :whopper: || :doge-face: '${env.JOB_NAME} || :buildy_spin: ${env.BUILD_NUMBER} || (${env.BUILD_URL})")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment