13

Here is some documentation on the Jenkins pipeline linter and its commands. Do you need to validate before a commit? If not, it would be really trivial to run the linting command prior to your pipeline running, and simply fail if it does not pass. From Command-line Pipeline Linter: Jenkins can validate, or "lint", a Declarative Pipeline from the ...


5

You can try to use scripting syntax into the declarative pipeline. For some step there is no declarative syntax yet. I had the same problem trying to use the docker global variable as a step. stage ('Docker Build') { steps { // prepare docker build context sh "cp target/project.war ./tmp-docker-build-context" // Build and push image with ...


4

When using Declarative Pipelines you can achieve the goal of running some steps only for certain branches by using the when directive with the build-in condition branch: branch Execute the stage when the branch being built matches the branch pattern (ANT style path glob) given, for example: when { branch 'master' }. Note that this only works on a ...


3

Just avoid the docker DSL; it is incompatible with Declarative. Also avoid script blocks. Simply withDockerServer([uri: "tcp://<my-docker-socket>"]) { withDockerRegistry([credentialsId: 'docker-registry-credentials', url: "https://<my-docker-registry>/"]) { sh ''' docker build -t whatever . docker push whatever # or ...


3

There's a resolveScm step implemented by the Pipeline: Multibranch plugin: checkout resolveScm(source: [$class: 'GitSCMSource', credentialsId: '<credentialsId>', id: '_', remote: 'https://your.git.remote/repository.git', traits: [[$class: ...


2

Sometimes it is easier to ask forgiveness than permission. Instead of trying to figure out whether branch b exists, just try to check it out. If it fails, checkout branch a. script { try { checkout([ $class: 'GitSCM', branches: [[name: 'b']], userRemoteConfigs: [[url: url]] ]) } ...


1

pipeline { agent any stages { stage('Tests') { when { branch 'master' } steps { echo 'foo' } } }


1

If you run a script you have to specify where the output goes. sh(returnStdout: true, script: "echo 'this should not be logged it is secret'") returnStdout: true is standard, set it to false and nothing is shown If you want to capture the output do. def msg = sh(returnStdout: false, script: "echo 'this should not be logged it is secret'")...


1

Added a pipeline-stage-view plugin


1

Have you looked at the Matrix project plugin? Multi-Configuration Projects A multi-configuration project is useful for instances where your builds will make many similar build steps, and you would otherwise be duplicating steps. Configuration matrix The Configuration Matrix allows you to specify what steps to duplicate, and create a multiple-axis graph of ...


1

node { checkout scm app = docker.build("test-image","-f path/to/dockerfile .") }


1

From the official instructions on building Docker images with Jenkins Pipeline: The build() method builds the Dockerfile in the current directory by default. This can be overridden by providing a directory path containing a Dockerfile as the second argument of the build() method, for example: node { checkout scm def testImage = docker.build(...


1

There seems to be an open issue at the moment. Another user experienced the same issue as well and added the following comment: why is there a difference between node context and stage context


Only top voted, non community-wiki answers of a minimum length are eligible