Last active
August 21, 2017 09:53
-
-
Save tnolet/628285638fcc7dc959a702cd4c4513ad to your computer and use it in GitHub Desktop.
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 vampDeploymentName = 'simpleservice' | |
def vampHost = 'http://10.0.1.134:3232' | |
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('Deploy to Vamp') { | |
sh "curl -X POST --data-binary @vamp_blueprint.yml ${vampHost}/api/v1/blueprints -H 'Content-Type: application/x-yaml'" | |
sh "curl -X PUT --data-binary @vamp_blueprint.yml ${vampHost}/api/v1/deployments/simpleservice -H 'Content-Type: application/x-yaml'" | |
sh "curl -X PUT --data-binary @gateway.yml ${vampHost}/api/v1/gateways/simpleservice/simpleservice/web -H 'Content-Type: application/x-yaml'" | |
} | |
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