Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Avoid excess Pipeline steps #83

Open
jglick opened this issue Nov 9, 2018 · 1 comment
Open

Avoid excess Pipeline steps #83

jglick opened this issue Nov 9, 2018 · 1 comment
Labels
enhancement New feature or request kubecd-triaged Triaged by Mark

Comments

@jglick
Copy link

jglick commented Nov 9, 2018

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 environments 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request kubecd-triaged Triaged by Mark
Projects
None yet
Development

No branches or pull requests

2 participants