Hero Image
Some Jenkinsfile examples

Some Jenkinsfile examples Parallel #!/usr/bin/env groovy pipeline { agent any stages { stage("Build") { steps { sh 'mvn -v' } } stage("Testing") { parallel { stage("Unit Tests") { agent { docker 'openjdk:7-jdk-alpine' } steps { sh 'java -version' } } stage("Functional Tests") { agent { docker 'openjdk:8-jdk-alpine' } steps { sh 'java -version' } } stage("Integration Tests") { steps { sh 'java -version' } } } } stage("Deploy") { steps { echo "Deploy!" } } } } When #!/usr/bin/env groovy pipeline { agent any environment { VALUE_ONE = '1' VALUE_TWO = '2' VALUE_THREE = '3' } stages { // skip a stage while creating the pipeline stage("A stage to be skipped") { when { expression { false } //skip this stage } steps { echo 'This step will never be run' } } // Execute when branch = 'master' stage("BASIC WHEN - Branch") { when { branch 'master' } steps { echo 'BASIC WHEN - Master Branch!' } } // Expression based when example with AND stage('WHEN EXPRESSION with AND') { when { expression { VALUE_ONE == '1' && VALUE_THREE == '3' } } steps { echo 'WHEN with AND expression works!' } } // Expression based when example stage('WHEN EXPRESSION with OR') { when { expression { VALUE_ONE == '1' || VALUE_THREE == '2' } } steps { echo 'WHEN with OR expression works!' } } // When - AllOf Example stage("AllOf") { when { allOf { environment name:'VALUE_ONE', value: '1' environment name:'VALUE_TWO', value: '2' } } steps { echo "AllOf Works!!" } } // When - Not AnyOf Example stage("Not AnyOf") { when { not { anyOf { branch "development" environment name:'VALUE_TWO', value: '4' } } } steps { echo "Not AnyOf - Works!" } } } }

Hero Image
Shell Script Study Notes

Shell Script Study Notes Arithmetic operations val=`expr $a + $b` Operators Symbol Description Example ! NOT [ ! false ] -o OR [ $a -lt 20 -o $b -gt 20 ] -a AND [ $a -lt 20 -a $b -gt 20 ] = equality check [ $a = $b ] != inequality check [ $a != $b ] -z string length is 0, returns true if 0 [ -z $a ] -n string length is not 0, returns true if not 0 [ -n $a ] str check whether string is empty, true if not [ $a ] -b check whether file is a block device [ -b $file ] -c check whether file is a character device .. -d check whether file is a directory [ -d $file ] -f check whether file is a regular file [ -f $file ] -r check whether file is readable .. -w check whether file is writable .. -x check whether file is executable .. -s check whether file is empty .. -e check whether file exists .. Special variables Variable Meaning $0 file name of the current script $n arguments passed to a script or function; n is the position $# number of arguments passed to a script or function $* all arguments as a single word, e.g., “1 2 3” $@ all arguments as separate words, e.g., “1” “2” “3” $? exit status of the last command or return value of a function $$ current shell process ID; for scripts, the PID of the script process POSIX program exit statuses Code Meaning 0 command exited successfully > 0 failure during redirection or word expansion (~, variables, commands, arithmetic, and word splitting) 1 - 125 command exited unsuccessfully; specific meanings are command-defined 126 command found but file is not executable 127 command not found > 128 command died from a signal Input/output redirection Command Description command > file redirect output to file command > file redirect output to file by appending n > file redirect file descriptor n to file n » file redirect file descriptor n to file by appending n >& m merge output file m and n n <& m merge input file m and n « tag use content between start tag and end tag as input File include Use . or source to include files.