Jenkins Pipeline Syntax: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 76: Line 76:
  }
  }
</syntaxhighlight>
</syntaxhighlight>
=Step Reference=
=Basic Steps Reference=
 
====echo====
====error====
====readFile====
====stash====


* [https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#stash-stash-some-files-to-be-used-later-in-the-build stash]
* [https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#stash-stash-some-files-to-be-used-later-in-the-build stash]
=Steps=
These steps are used invoking on <code>stage.</code>. In a Jenkinsfile, and inside a stage, invoke on <code>this.</code> or simply invoking directly like below:
* read-file step. Reading a file from the workspace: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace
<syntaxhighlight lang='groovy'>
def versionFile = readFile("${stage.WORKSPACE}/terraform/my-module/VERSION")
</syntaxhighlight>
* error https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#error-error-signal

Revision as of 17:33, 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

echo

error

readFile

stash

Steps

These steps are used invoking on stage.. In a Jenkinsfile, and inside a stage, invoke on this. or simply invoking directly like below:

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