Jenkins Pipeline Syntax: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 85: Line 85:
====readFile====
====readFile====
{{External|https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace}}
{{External|https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace}}
Reading a file from the workspace.
Read a file from the workspace.
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
def versionFile = readFile("${stage.WORKSPACE}/terraform/my-module/VERSION")
def versionFile = readFile("${stage.WORKSPACE}/terraform/my-module/VERSION")
</syntaxhighlight>
</syntaxhighlight>
====stash====
====stash====
{{External|https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#stash-stash-some-files-to-be-used-later-in-the-build}}
{{External|https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#stash-stash-some-files-to-be-used-later-in-the-build}}

Revision as of 17:35, 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'
             }
         }
     }
 }

Basic Steps Reference

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

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