Last active
February 13, 2017 23:14
-
-
Save catherinetcai/269f6b23e86b2f134482d2c497a53c49 to your computer and use it in GitHub Desktop.
Jenkinsfile Helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ** 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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ** 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 .") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage "Checkout" | |
git url: 'https://github.com/sample/project', credentialsId: 'your-credentials-here', branch: 'optional-branch' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ** 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