|
| 1 | +pipeline { |
| 2 | + agent { |
| 3 | + label "jenkins-ruby" |
| 4 | + } |
| 5 | + environment { |
| 6 | + ORG = 'jenkinsx' |
| 7 | + APP_NAME = 'ecsdemo-frontend' |
| 8 | + CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum') |
| 9 | + } |
| 10 | + stages { |
| 11 | + stage('CI Build and push snapshot') { |
| 12 | + when { |
| 13 | + branch 'PR-*' |
| 14 | + } |
| 15 | + environment { |
| 16 | + PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER" |
| 17 | + PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase() |
| 18 | + HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase() |
| 19 | + } |
| 20 | + steps { |
| 21 | + container('ruby') { |
| 22 | + sh "docker build -t $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION ." |
| 23 | + sh "docker push $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION" |
| 24 | + } |
| 25 | + |
| 26 | + dir ('./charts/preview') { |
| 27 | + container('ruby') { |
| 28 | + sh "make preview" |
| 29 | + sh "jx preview --app $APP_NAME --dir ../.." |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + stage('Build Release') { |
| 35 | + when { |
| 36 | + branch 'master' |
| 37 | + } |
| 38 | + steps { |
| 39 | + container('ruby') { |
| 40 | + // ensure we're not on a detached head |
| 41 | + sh "git checkout master" |
| 42 | + // until we switch to the new kubernetes / jenkins credential implementation use git credentials store |
| 43 | + sh "git config --global credential.helper store" |
| 44 | + // so we can retrieve the version in later steps |
| 45 | + sh "echo \$(jx-release-version) > VERSION" |
| 46 | + } |
| 47 | + dir ('./charts/ecsdemo-frontend') { |
| 48 | + container('ruby') { |
| 49 | + sh "jx step git credentials" |
| 50 | + sh "make tag" |
| 51 | + } |
| 52 | + } |
| 53 | + container('ruby') { |
| 54 | + sh "docker build -t $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION) ." |
| 55 | + sh "docker push $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)" |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + stage('Promote to Environments') { |
| 60 | + when { |
| 61 | + branch 'master' |
| 62 | + } |
| 63 | + steps { |
| 64 | + dir ('./charts/ecsdemo-frontend') { |
| 65 | + container('ruby') { |
| 66 | + sh 'jx step changelog --version v\$(cat ../../VERSION)' |
| 67 | + |
| 68 | + // release the helm chart |
| 69 | + sh 'jx step helm release' |
| 70 | + |
| 71 | + // promote through all 'Auto' promotion Environments |
| 72 | + sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)' |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + post { |
| 79 | + always { |
| 80 | + cleanWs() |
| 81 | + } |
| 82 | + } |
| 83 | + } |
0 commit comments