Skip to content

Instantly share code, notes, and snippets.

@stefan-wegener
Last active July 11, 2018 07:35
Show Gist options
  • Select an option

  • Save stefan-wegener/f30034d52093976406760c97dbeb4adc to your computer and use it in GitHub Desktop.

Select an option

Save stefan-wegener/f30034d52093976406760c97dbeb4adc to your computer and use it in GitHub Desktop.
Jenkins Pipeline

Variable usage

echo '${test}' // prints ${test}
echo "${test}" // prints value of variable

Loops

  int num = numParameter as Integer //numParameter is String Parameter in Job
  for(int i = 0; i < num; i++) {
    //...
  }

Error handling

  def err = null

  //somewhere in Pipeline:
  try {
    /...
  } catch (caughtError) {
    err = caughtError
  }

  //rethrow error at end of Pipeline to fail build
  if (err) {
    throw err
  }

Read contents of a file and parse them

  def filenames = readFile 'filenames.txt'
  def filenameArray = filenames.split(",")
  for(int i = 0; i < filenameArray.size(); i++) {
    //... filenameArray[i]
  }

Ensure correct log-output ordering: sh "stdbuf -oL mycommand"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment