Last active
August 16, 2017 12:32
-
-
Save tnolet/3f4a3cfe82d883980e787746ba51045d to your computer and use it in GitHub Desktop.
vamp+dcos+jenkins guide: deploy initial blueprint
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
#!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