|
| 1 | +pipeline { |
| 2 | + agent { |
| 3 | + label "jenkins-python" |
| 4 | + } |
| 5 | + environment { |
| 6 | + ORG = 'gitcoinco' |
| 7 | + APP_NAME = 'web' |
| 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('python') { |
| 22 | + sh "python -m unittest" |
| 23 | + |
| 24 | + sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml' |
| 25 | + |
| 26 | + |
| 27 | + sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION" |
| 28 | + } |
| 29 | + |
| 30 | + dir ('./charts/preview') { |
| 31 | + container('python') { |
| 32 | + sh "make preview" |
| 33 | + sh "jx preview --app $APP_NAME --dir ../.." |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + stage('Build Release') { |
| 39 | + when { |
| 40 | + branch 'master' |
| 41 | + } |
| 42 | + steps { |
| 43 | + container('python') { |
| 44 | + // ensure we're not on a detached head |
| 45 | + sh "git checkout master" |
| 46 | + sh "git config --global credential.helper store" |
| 47 | + |
| 48 | + sh "jx step git credentials" |
| 49 | + // so we can retrieve the version in later steps |
| 50 | + sh "echo \$(jx-release-version) > VERSION" |
| 51 | + } |
| 52 | + dir ('./charts/web') { |
| 53 | + container('python') { |
| 54 | + sh "make tag" |
| 55 | + } |
| 56 | + } |
| 57 | + container('python') { |
| 58 | + sh "python -m unittest" |
| 59 | + |
| 60 | + sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml' |
| 61 | + |
| 62 | + sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)" |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + stage('Promote to Environments') { |
| 67 | + when { |
| 68 | + branch 'master' |
| 69 | + } |
| 70 | + steps { |
| 71 | + dir ('./charts/web') { |
| 72 | + container('python') { |
| 73 | + sh 'jx step changelog --version v\$(cat ../../VERSION)' |
| 74 | + |
| 75 | + // release the helm chart |
| 76 | + sh 'jx step helm release' |
| 77 | + |
| 78 | + // promote through all 'Auto' promotion Environments |
| 79 | + sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)' |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + post { |
| 86 | + always { |
| 87 | + cleanWs() |
| 88 | + } |
| 89 | + } |
| 90 | + } |
0 commit comments