Skip to content

Instantly share code, notes, and snippets.

@icheko
Last active July 22, 2019 20:23
Show Gist options
  • Save icheko/5b3f3746b4b454c7beecc2cd7bdf6bfd to your computer and use it in GitHub Desktop.
Save icheko/5b3f3746b4b454c7beecc2cd7bdf6bfd to your computer and use it in GitHub Desktop.
/*
This function is used to mount the Heroku .netrc
file into the heroku-cli container. The value of the
env variable should be of the form:
/Users/jose.s.pacheco/.netrc:/root/.netrc
On production env.USER is defined as cloudbees so it
returns the production .netrc file
*/
def mount_heroku_auth() {
node{
if (env.USER == 'cloudbees') {
echo 'mount_heroku_auth: returning HEROKU_AUTH_NETRC_PROD'
return env.HEROKU_AUTH_NETRC_PROD
} else {
return env.HEROKU_AUTH_NETRC
}
}
}
pipeline{
agent none
stage('\u27A1 Git Checkout') {
agent any
when {
environment ignoreCase: true, name: 'USER', value: 'cloudbees'
}
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'jose-s-pacheco-pat',
url: 'https://url/jose-s-pacheco/repo.git'
]]
])
sh 'ls -al'
}
}
stage('\u27A1 Build App'){
agent {
docker {
image 'node:10-alpine'
args '-u root -v $USER_HOME/node_modules:/workspace/jenkins/workspace/job/node_modules' // this second mount improves reruns on local
}
}
steps {
sh 'npm install -g @angular/cli@7.3.9'
sh 'npm install'
sh 'ng version'
sh "ng build --configuration=$ENVIRONMENT"
}
}
stage('\u27A1 Heroku Deployment'){
agent {
docker {
image 'dickeyxxx/heroku-cli:latest'
args '-u root -v ' + mount_heroku_auth() // heroku command needs root
}
}
steps {
sh 'rm -Rfv heroku-deployment'
sh "heroku git:clone -a heroku-app heroku-deployment"
dir('heroku-deployment'){
sh 'heroku auth:whoami'
sh "heroku info heroku-app"
sh 'git config --global user.email "icheko@gmail.com"'
sh 'git config --global user.name "Jose Pacheco"'
sh 'cp -Rfv ../dist .'
sh 'cp ../server.js .'
sh 'cp ../package.json .'
sh 'cp ../package-lock.json .'
echo ''
echo '--------------------------------------------'
sh 'ls -al'
sh 'git add .'
sh 'git commit -m "Heroku Deployment" || echo "No changes to commit"'
sh 'git push heroku master'
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment