Skip to content

Instantly share code, notes, and snippets.

@affixalex
Created September 3, 2018 20:14
Show Gist options
  • Save affixalex/18b0cb85f05f811a2b470ca871d7052c to your computer and use it in GitHub Desktop.
Save affixalex/18b0cb85f05f811a2b470ca871d7052c to your computer and use it in GitHub Desktop.
pipeline {
agent {
label "jenkins-ruby"
}
environment {
ORG = 'jenkinsx'
APP_NAME = 'dashboard'
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
}
stages {
stage('CI Build and push snapshot') {
when {
branch 'PR-*'
}
environment {
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
}
steps {
container('ruby') {
sh "docker build -t \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:$PREVIEW_VERSION ."
sh "docker push \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:$PREVIEW_VERSION"
}
dir ('./charts/preview') {
container('ruby') {
sh "make preview"
sh "jx preview --app $APP_NAME --dir ../.."
}
}
}
}
stage('Build Release') {
when {
branch 'master'
}
steps {
container('ruby') {
// ensure we're not on a detached head
sh "git checkout master"
// until we switch to the new kubernetes / jenkins credential implementation use git credentials store
sh "git config --global credential.helper store"
// so we can retrieve the version in later steps
sh "echo \$(GITHUB_AUTH_TOKEN=\$(echo | git credential-store get | grep -o -P '(?<=password=).*'); jx-release-version) > VERSION"
}
dir ('./charts/ruby') {
container('ruby') {
sh "jx step git credentials"
sh "make tag"
}
}
container('ruby') {
sh "docker build -t \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:\$(cat VERSION) ."
sh "docker push \$JENKINS_X_DOCKER_REGISTRY_SERVICE_HOST:\$JENKINS_X_DOCKER_REGISTRY_SERVICE_PORT/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}
stage('Promote to Environments') {
when {
branch 'master'
}
steps {
dir ('./charts/ruby') {
container('ruby') {
sh 'jx step changelog --version v\$(cat ../../VERSION)'
// release the helm chart
sh 'make release'
// promote through all 'Auto' promotion Environments
sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment