Skip to content

Instantly share code, notes, and snippets.

@rtyler
Last active June 20, 2016 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtyler/47bd1685af4cde922a4bacfad453fab8 to your computer and use it in GitHub Desktop.
Save rtyler/47bd1685af4cde922a4bacfad453fab8 to your computer and use it in GitHub Desktop.

pingback step

The idea for a pingback step would be to account for delivery pipelines that are completed, or interacted with, by external services and tools.

The Problem

The jenkins-infra project is a good example of this, as would any other r10k-based Puppet delivery pipeline. The Puppet master (central server) is responsible for the "last mile" of delivery, meaning that code isn’t truly deployed until:

  1. it is deployed to the Puppet master

  2. Puppet agents pick up, and apply, the correspondnig catalogue changes

The solution

pingback could operate similar to input insofar as introducing a blocking step inside of the Jenkins Pipeline DSL. This would allow an external service to make a well-formed HTTP POST request to a URL, such as http://jenkins.example.com/job/puppet-delivery/pingback, and resume a delivery pipeline.

#!/usr/bin/env groovy
import groovy.json.JsonSlurperClassic
node('docker') {
stage "Lint"
docker.image('rvm').inside {
checkout scm
sh 'bundle exec rake lint'
}
stage 'RSpec'
docker.image('rvm').inside {
sh 'bundle exec rake spec'
}
}
stage 'Prepare Deploy'
node {
checkout scm
sh './some-magic-merge.sh'
}
stage 'Deploy'
pingback(timeout: 30.MINUTES, credentials: ['my-preconfigured-creds']) { url, body, headers ->
echo "Pinged back at ${url}"
def json = new JsonSlurperClassic().parseText(body)
if (json['status'] == 'error') {
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: "infra@lists.jenkins-ci.org",
sendToIndividuals: true])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment