Skip to content

Instantly share code, notes, and snippets.

@tnolet
Last active August 16, 2017 12:32
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 tnolet/3f4a3cfe82d883980e787746ba51045d to your computer and use it in GitHub Desktop.
Save tnolet/3f4a3cfe82d883980e787746ba51045d to your computer and use it in GitHub Desktop.
vamp+dcos+jenkins guide: deploy initial blueprint
#!groovy
node {
def nodeHome = tool name: '8.3.0', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${nodeHome}/bin:${env.PATH}"
// !! Replace these with your own settings !!
def gitRepo = 'https://github.com/magneticio/simpleservice/'
def dockerHub = 'https://registry.hub.docker.com'
def dockerHubCreds = 'docker-hub-login'
def dockerRepo = 'magneticio'
def dockerImageName = 'simpleservice'
def appVersion
def dockerImage
currentBuild.result = "SUCCESS"
try {
stage('Checkout'){
git url: gitRepo, branch: 'master'
appVersion = sh (
script: 'node -p -e "require(\'./package.json\').version"',
returnStdout: true
).trim()
}
stage('Install') {
sh 'npm install'
}
stage('Test') {
sh 'npm test'
}
stage('Build Docker image') {
dockerImage = docker.build("${dockerRepo}/${dockerImageName}")
}
stage('Push Docker image') {
docker.withRegistry(dockerHub, dockerHubCreds) {
dockerImage.push(appVersion)
dockerImage.push("latest")
}
}
stage('Cleanup') {
sh 'rm node_modules -rf'
}
}
catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment