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

Avoid excess Pipeline steps #83

Description

@jglick

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions