Skip to content

Instantly share code, notes, and snippets.

@safizn
Last active February 28, 2017 13:37
Show Gist options
  • Save safizn/3c8c9f300470be8c5a965c28b8705595 to your computer and use it in GitHub Desktop.
Save safizn/3c8c9f300470be8c5a965c28b8705595 to your computer and use it in GitHub Desktop.
Jenkins
# Delete all build history of specific job pipeline.
# http://codeketchup.blogspot.co.il/2016/05/how-to-clean-and-reset-jenkins-build.html
def jobName = "education-webapp"
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()
// for testing:
// sh 'docker run alpine sleep 1; exit 1'
// sh 'docker run myuserindocker/deployment-environment node -e "process.exit(1)"'
// Issue - docker-compose doesn't propagate non-zero code to shell command. Therefore CI build doesn't catch the failure of the container.
// Fixing this issue could be using 'docker-compose run' commands for shortlived services. instead of docker-compose up.
// http://stackoverflow.com/questions/29568352/using-docker-compose-with-ci-how-to-deal-with-exit-codes-and-daemonized-linked
// http://blog.ministryofprogramming.com/docker-compose-and-exit-codes/
# Propagate internal exit code of docker-compose to external shell exit code.
sh '''
docker run myuserindocker/deployment-environment node -e "process.exit(1)" && echo $?;
docker-compose -f ./setup/container/deployment.dockerCompose.yml ps -q | xargs docker inspect -f '{{ .State.ExitCode }}' | while read code; do
if [ "$code" == "1" ]; then
exit -1
fi
done
'''
// Example for testing
sh '''
docker run alpine /bin/sh -c exit 1 || echo $?;
docker run myuserindocker/deployment-environment node -e "process.exit(0)" && echo $?;
docker-compose -f ./setup/container/deployment.dockerCompose.yml ps -q | xargs docker inspect -f '{{ .State.ExitCode }}' | while read code; do
if [ "$code" == "1" ]; then
exit -1
fi
done
'''
# Check this plugin. - couldn't find settings after activating .
# https://wiki.jenkins-ci.org/display/JENKINS/Text-finder+Plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment