Jenkins Pipeline Syntax: Difference between revisions
(→node) |
(→node) |
||
Line 84: | Line 84: | ||
Allocates an executor or a node, typically a worker, and run the enclosed code in the context of the workspace of that worker. Node may take a label name, computer name or an expression. | Allocates an executor or a node, typically a worker, and run the enclosed code in the context of the workspace of that worker. Node may take a label name, computer name or an expression. | ||
The labels are declared on workers when they are defined in the master configuration, in their respective "clouds". | |||
====sh==== | ====sh==== |
Revision as of 04:41, 22 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
node
Allocates an executor or a node, typically a worker, and run the enclosed code in the context of the workspace of that worker. Node may take a label name, computer name or an expression.
The labels are declared on workers when they are defined in the master configuration, in their respective "clouds".
sh
Shell Script.
ws
Allocate workspace.
build
This is how a main pipeline launches in execution a subordinate pipeline.
This is how we may be able to return the result: https://support.cloudbees.com/hc/en-us/articles/218554077-How-to-set-current-build-result-in-Pipeline
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
Change current directory.
echo
error
readFile
Read a file from the workspace.
def versionFile = readFile("${stage.WORKSPACE}/terraform/my-module/VERSION")