Jenkins Pipeline Syntax: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 97: Line 97:
Allocate workspace.
Allocate workspace.


==Basic Steps Reference==
==Basic Steps==


These basic steps are used invoking on <code>stage.</code>. In a Jenkinsfile, and inside a stage, invoke on <code>this.</code> or simply invoking directly, without qualifying.
These basic steps are used invoking on <code>stage.</code>. In a Jenkinsfile, and inside a stage, invoke on <code>this.</code> or simply invoking directly, without qualifying.

Revision as of 18:11, 21 November 2019

External

Internal

Scripted Pipeline

 node {
 
     echo 'Pipeline logic starts'
 
     stage('Build') {
        // ...
     }
     stage('Test') {
        // ...
     }
     stage('Deploy') {
        // ...
     }

Parallel Stages

stage("tests") {

    parallel(

        "unit tests": {

             // run unit tests 
         },
         "coverage tests": {

             // run coverage tests
         }
     )
}

Declarative Pipeline

 pipeline { 
     agent any 
     options {
         skipStagesAfterUnstable()
     }
     stages {
         stage('Build') { 
             steps { 
                 sh 'make' 
             }
         }
         stage('Test'){
             steps {
                 sh 'make check'
                 junit 'reports/**/*.xml' 
             }
         }
         stage('Deploy') {
             steps {
                 sh 'make publish'
             }
         }
     }
 }

Pipeline Steps

https://jenkins.io/doc/pipeline/steps/

node

https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-node-allocate-node

Allocate node.

sh

https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-sh-shell-script

Shell Script.

ws

https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-ws-allocate-workspace

Allocate workspace.

Basic Steps

These basic steps are used invoking on stage.. In a Jenkinsfile, and inside a stage, invoke on this. or simply invoking directly, without qualifying.

dir

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#-dir-change-current-directory

Change current directory.

echo

error

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#error-error-signal

readFile

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace

Read a file from the workspace.

def versionFile = readFile("${stage.WORKSPACE}/terraform/my-module/VERSION")

stash

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#stash-stash-some-files-to-be-used-later-in-the-build