Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a Jenkins pipeline multiline /multi-line string parameter

I'm converting a bunch of jobs to use the Jenkins pipeline language.

In plain/normal Jenkins we can use parameter types including:

  • string
  • boolean
  • choice, and also
  • multi-line string.

A parameter using one of these types will pop up and prompt the user for input when they run the Jenkins job.

The available parameter types for Jenkins pipeline are: (According to here).

  • booleanParam
  • choice
  • file
  • text
  • password
  • run
  • string

There is no multiline string input parameter listed for pipeline. The Jenkins documentation say the documentation is "young" and still incomplete.

Has anyone managed to get a multi-line string input parameter working with the Jenkins pipeline?

Multi-line string parameters are in the out-of-the-box Jenkins package, but doesn't seem to be there in the pipeline.

like image 884
CyclingDave Avatar asked Jul 13 '18 15:07

CyclingDave


2 Answers

Multi-line string parameters are text parameters in pipeline syntax. They are described on the Jenkins Pipeline Syntax page.

Example:

parameters { text(name: 'DEPLOY_TEXT', defaultValue: 'One\nTwo\nThree\n', description: '') }
like image 163
Tony B Avatar answered Oct 19 '22 17:10

Tony B


I discovered the solution by looking at the Jenkins source code:

parameters{ text(name: 'mytextparam', 
                 defaultValue: 'Default lines for the parameter', 
                 description: 'A description of this param')    
}

This pops up a multi-line text input prompt which becomes the parameter value which you can refer to later as params.mytextparam

This is not documented in the Jenkins Pipeline documentation, so there might be issues like it being unsupported or withdrawn in a future release. Or it could go the other way and they might document it in the next release.

like image 21
CyclingDave Avatar answered Oct 19 '22 16:10

CyclingDave