From 021ec664d4124b47d1c6a9e536907396d7e9375c Mon Sep 17 00:00:00 2001
From: ejidike esther -xe flags
(you can specify set +e and/or set +x to disable those).
A few examples of usage include:
+ + Creating an output folder +sh "mkdir -p output"
sh "ls -la ${pwd()}"
sh "curl -X POST --data-urlencode \'payload=${payload}\' ${slackURL}"
sh 'mvn test'
The triple-double-quote (""") string literal syntax allows for variable/expression substitution (interpolation), so the backslash (\) is interpreted as a special character "escape".
+Since the first open parentheses is not such a special character, Groovy compilation fails. If your intent is to have literal backslashes in the resulting string, you need to escape the backslashes. That is, use a double-backslash (\\) to substitute for one literal backslash
+sh ("""
+ sed "s/(AssemblyInformationalVersion\\(\\")(.*)(\\")/\\1${productVersion}\\3/g"
+ AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r
+ """)
+
For double quoted string, Groovy will do interpolation on the string firstly.
+Because the variables are runtime variables of the shell, rather than the variables of Groovy runtime. Groovy can't find the responding value from Groovy variable stack to replace the variables during interpolation.
+So you need to escape all $ if you use double quotes or simply use single quotes which does not support interpolation
+sh(returnStdout: true, script: "cd \$it; PLAN=\$(terragrunt plan --terragrunt-source-update | landscape);
+ echo \$PLAN; CHANGES=\$(echo \$PLAN | tail -2); echo \$CHANGES"
sh "mkdir -p output"
sh "ls -la ${pwd()}"
-xe flags
(you can specify set +e and/or set +x to disable those).
- A few examples of usage include:
+Use the Pipeline Snippet Generator to generate a sample pipeline script for the sh step + A few examples of usage include:
Creating an output foldersh "mkdir -p output"
sh "ls -la ${pwd()}"
The triple-double-quote (""") string literal syntax allows for variable/expression substitution (interpolation), so the backslash (\) is interpreted as a special character "escape".
Since the first open parentheses is not such a special character, Groovy compilation fails. If your intent is to have literal backslashes in the resulting string, you need to escape the backslashes. That is, use a double-backslash (\\) to substitute for one literal backslash
+Use the Pipeline Snippet Generator to generate this example
For double quoted string, Groovy will do interpolation on the string firstly. Because the variables are runtime variables of the shell, rather than the variables of Groovy runtime. Groovy can't find the responding value from Groovy variable stack to replace the variables during interpolation. So you need to escape all $ if you use double quotes or simply use single quotes which does not support interpolation Use the Pipeline Snippet Generator to generate this example The bat step is used to run pipelines on a windows environment,
+ if your pipeline will run on a Linux environment, use the To use the bat step, you have to first point it to the path where your bat file exists, and then 'call' command to trigger that bat file. Examples below: Use the Pipeline Snippet Generator to generate the example An example of a declarative pipeline executing a bat step with the command set Use the Pipeline Snippet Generator to generate this example Print out all the environment variables seen by Windows. Print out the content of the PATH environment variable on Windows Add the keyword call when running a multi-line script and need the commands to execute sequentially
+ Failure to do so will result in only the first line
+ executing. You can also use ''&'' to chain commands into a single line
+but this will make your commands hard to read and prone to mistakes. Use the Pipeline Snippet Generator to generate this example The return status step is used to return the exit status of a script. 0 equals true in shell. An exit code
+ of 1 will cause jenkins to abort.
+ Use the
+ Pipeline Snippet Generator
+ to generate this example by checking the You can use an if statement to ascertain if the exit status returned 0 or not by assigning your script to
+ a variable.
+ While it is not advisable, use See sh ("""
sed "s/(AssemblyInformationalVersion\\(\\")(.*)(\\")/\\1${productVersion}\\3/g"
AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r
@@ -37,6 +38,7 @@
sh(returnStdout: true, script: "cd \$it; PLAN=\$(terragrunt plan --terragrunt-source-update | landscape);
echo \$PLAN; CHANGES=\$(echo \$PLAN | tail -2); echo \$CHANGES"returnStdout flag, you probably wish to prefix this with @,
lest the command itself be included in the output.
+
+sh step.
+bat 'C:\\example\\mybat.bat'
+
+ pipeline {
+ agent any
+ stages {
+ stage('Build') {
+ steps {
+ bat 'set'
+ }
+ }
+ }
+ }
+
+echo bat(returnStdout: true, script: 'set')bat 'echo %PATH%'
+
+ bat """
+ call c:\path\to\conda activate my_env
+ cd c:\\path\\to\\scripts
+ call python test.py ${argument}
+ """
+
+returnStatus option
+sh returnStatus: true, script: 'mvn test'int status = sh returnStatus: true, script: 'mvn test'
+ if (status != 0){
+ //Take Action
+ }
+
+set +e to ignore the exit status code 1 when running shell scriptsh documentation for this value