Skip to content

Instantly share code, notes, and snippets.

@catherinetcai
Last active February 13, 2017 23:14
Show Gist options
  • Save catherinetcai/269f6b23e86b2f134482d2c497a53c49 to your computer and use it in GitHub Desktop.
Save catherinetcai/269f6b23e86b2f134482d2c497a53c49 to your computer and use it in GitHub Desktop.
Jenkinsfile Helpers
// ** DUMP CREDENTIALS INTO AN ENV VAR **
node {
def cert="cert-id"
withCredentials([[$class: 'FileBinding', credentialsId: "${cert}", variable: 'REG_CERT']]) {
sh 'cat ${env.REG_CERT}' // Maybe don't actually cat it, but there ya go
}
}
// ** DOCKER BUILD AND PULL FROM A PRIVATE DOCKER HUB REPOSITORY
node {
def app="example"
def hub="https://index.docker.io/v1/"
def hubCreds="credential-ID-here" //You can set via a regular Jenkins credential with username and password
stage 'Docker build'
docker.withRegistry("${hub}", "${hubCreds}") {
docker.build("${app}")
// If you want to pass a specific Dockerfile, then do this
// docker.build("${app}", "-f custom.Dockerfile .")
}
}
stage "Checkout"
git url: 'https://github.com/sample/project', credentialsId: 'your-credentials-here', branch: 'optional-branch'
// ** CUSTOM JAVA AND MAVEN **
// This shows you how to add a custom Java and Maven to your path
// Used this for DC/OS's slaves, which are not provisioned with Maven like the master
// You need to make sure that you specify the version of Java and Maven in the global tool configuration view in Jenkins first
node {
stage 'Configuration'
env.JAVA_HOME = "${tool 'JDK 8u101'}" //Swap out JDK 8u101 with whatever is the ID of the Java version you specified
env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
env.PATH = "${tool 'Maven 3'}/bin:${env.PATH}" //Swap out Maven 3 with Maven ID version
sh 'java -version'
sh 'mvn -v'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment