draft-packs
draft-packs copied to clipboard
Avoid excess Pipeline steps
When I look at for example this Maven Jenkinsfile
, I see way too much Pipeline script. There is no reason for any stage
to have more than one sh
step unless some other Pipeline step (not counting dir
) intervenes. For example,
sh "git config --global credential.helper store"
sh "jx step validate --min-jx-version 1.1.73"
sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
dir ('./charts/vertx-demo') {
sh "make tag"
}
sh 'mvn clean deploy'
sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml'
sh "jx step post build --image \$DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
would better be collapsed to
sh 'sh build-release.sh'
where that shell script is added to the repo:
#!/bin/sh -xe
git config --global credential.helper store
jx step validate --min-jx-version 1.1.73
jx step git credentials
export VERSION=$(jx-release-version)
mvn versions:set -DnewVersion=$VERSION
make -C charts/vertx-demo tag
mvn clean deploy
skaffold build -f skaffold.yaml
jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION
which is more readable and maintainable. Any per-stage
environment
s can also be inlined into the script; for example:
PREVIEW_NAMESPACE=$(echo APP_NAME-$BRANCH_NAME | tr '[A-Z]' '[a-z]')
Only the top-level environment
blocks are actually useful, for defining variables used in multiple stages and thus scripts.
Would be happy to file a PR, though I am not sure how you go about testing changes to draft packs.
Seems like this has since been refactored into @jenkins-x-buildpacks? example