diff --git a/Jenkinsfile b/Jenkinsfile index 1ca75e2f..7449a309 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,5 @@ +library 'pipeline-utils@master' + pipeline { agent { kubernetes { @@ -18,11 +20,11 @@ spec: requests: cpu: "512m" memory: "1024Mi" - ephemeral-storage: "4Gi" + ephemeral-storage: "2Gi" limits: cpu: "1024m" memory: "2048Mi" - ephemeral-storage: "8Gi" + ephemeral-storage: "2Gi" command: - /busybox/cat tty: true @@ -67,19 +69,10 @@ spec: stages { stage('Build') { steps { - container(name: 'kaniko', shell: '/busybox/sh') { - sh '''#!/busybox/sh - echo "Build stage" - /kaniko/executor --dockerfile ./Dockerfile \ - --context . \ - --verbosity debug \ - --no-push \ - --destination $IMAGE_NAME:$TAG1 \ - --destination $IMAGE_NAME:$TAG2 \ - --destination $IMAGE_NAME:$TAG3 \ - --destination $IMAGE_NAME:$TAG4 \ - --tarPath image.tar - ''' + script { + container(name: 'kaniko', shell: '/busybox/sh') { + kaniko.build("./Dockerfile", ["$IMAGE_NAME:$TAG1", "$IMAGE_NAME:$TAG2", "$IMAGE_NAME:$TAG3", "$IMAGE_NAME:$TAG4"]) + } } } post { @@ -97,34 +90,17 @@ spec: } stage('Publish') { steps { - container(name: 'crane', shell: '/busybox/sh') { - sh ''' - echo "Publish stage" - echo "$DOCKERHUB_CREDS_PSW" | crane auth login -u $DOCKERHUB_CREDS_USR --password-stdin $REGISTRY - crane push image.tar $IMAGE_NAME:$TAG1 - crane push image.tar $IMAGE_NAME:$TAG2 - if [ $BRANCH_NAME == "develop" ]; then - crane push image.tar $IMAGE_NAME:$TAG3 - elif [ $BRANCH_NAME == "master" ]; then - crane push image.tar $IMAGE_NAME:$TAG3 - crane push image.tar $IMAGE_NAME:$TAG4 - if [ $(git tag -l "$VERSION") ]; then - echo "ERROR: Tag with version $VERSION already exists! Exiting." - else - # Recover some things we've lost: - git config --global user.email "helx-dev@lists" - git config --global user.name "rencibuild rencibuild" - grep url .git/config - git checkout $BRANCH_NAME - - # Set the tag - SHA=$(git log --oneline | head -1 | awk '{print $1}') - git tag $VERSION "$SHA" - git remote set-url origin https://$GITHUB_CREDS_PSW@github.com/helxplatform/dug.git - git push origin --tags - fi - fi - ''' + script { + container(name: 'crane', shell: '/busybox/sh') { + def imageTagsPushAlways = ["$IMAGE_NAME:$TAG1", "$IMAGE_NAME:$TAG2"] + def imageTagsPushForDevelopBranch = ["$IMAGE_NAME:$TAG3"] + def imageTagsPushForMasterBranch = ["$IMAGE_NAME:$TAG4"] + image.publish( + imageTagsPushAlways, + imageTagsPushForDevelopBranch, + imageTagsPushForMasterBranch + ) + } } } }