Is it possible to make a parameterized scripted pipeline in Jenkins by listing the parameters in actual script, not in job config

I found a solution by experimentation so want to share it:

node {
  properties(
    [
        parameters(
            [string(defaultValue: '/data', name: 'Directory'),
             string(defaultValue: 'Dev', name: 'DEPLOY_ENV')]
            )

    ]
    )    

  ....
}

I highly recommend using the "Snippet Generator" for first time use of figuring this out. It will allow you to use a GUI that looks maybe exactly like the snapshot you shared above, to fill out the settings you want, and generate the appropriate syntax. For this question in-particular, select the sample step "properties: Set job properties" from the Snippet Generator

You can access the "Snippet Generator" from any Jenkins server by going to the /pipeline-syntax endpoint.

For more info on the snippet generator see: https://jenkins.io/doc/book/pipeline/getting-started/#snippet-generator


I did create it outside and it worked! Also, I'm using the boolean value and it's working like a charm on a scripted version

// Parameters for the build
properties([
  parameters([
     booleanParam(name: 'DEPLOY_SHA', defaultValue: false),
  ])
])

podTemplate(name: ptNameVersion, label: ptNameVersion, containers: [
...
...
] 

It shows the parameter

Screen Shot 2019-03-29 at 4 37 29 PM