Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

In a declarative pipeline, I can specify the parameter that the pipeline expects right in the pipeline script like so:

pipeline {    parameters([     string(name: 'DEPLOY_ENV', defaultValue: 'TESTING' )    ]) } 

is it possible do to in a scripted pipline? I know I can do this :

enter image description here

BUT, IS IT POSSIBLE TO DO THIS:

node{    parameters([     string(name: 'DEPLOY_ENV', defaultValue: 'TESTING' )    ]) } 
like image 711
Greg Bala Avatar asked Dec 12 '18 16:12

Greg Bala


People also ask

How to parameterize Jenkins jobs and pipelines?

Any Jenkins job or pipeline can be parameterized. All we have to do is check the box on the General settings tab that says This project is parameterized: Then we click the Add Parameter button. From here, we must specify several pieces of information:

How to create a custom build parameter in Jenkins?

15 First define your custom build parameter: pipeline { parameters { string( name: 'BuildConfiguration', defaultValue: 'Release', description: 'Configuration to build (Debug/Release/...)') It will automatically show up in page shown after you click "Build with parameters" from the Jenkins job page.

What are jenkinsfile parameters?

Jenkinsfile parameters are used to pass data to the build. There are three types of parameters we can pass - build, environment and pipeline variables

How do I pass data to a Jenkins job?

A build parameter allows us to pass data into our Jenkins jobs. Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we have to do is check the box on the General settings tab that says This project is parameterized:


1 Answers

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')]             )      ]     )        .... } 
like image 69
Greg Bala Avatar answered Sep 19 '22 06:09

Greg Bala