Last active
July 22, 2019 20:23
-
-
Save icheko/5b3f3746b4b454c7beecc2cd7bdf6bfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
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/[email protected]' | |
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 "[email protected]"' | |
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