How to create parameters in Jenkins without Jenkins UI

314 Views Asked by At

I am using Jenkins to run my automation test. But now my organisation is migrating to new Jenkins, due to which I will not be having access to some of the settings and options. Like, configure option is not there in the jenkins. So in that case, how can I create parameters in jenkins job to run the pipeline.

I tried jenkins declarative pipeline to create parameters. But that is also not working.

PLEASE PLEASE HELP!

1

There are 1 best solutions below

3
BenCourliss On

So you can create a Pipeline script/Jenkinsfile that uses the parameter directive as shown here https://www.jenkins.io/doc/book/pipeline/syntax/#parameters That entire website should be read so that you get an understanding of how Jenkins pipeline works.

pipeline {
    parameters {
        string(name: 'testString', defaultValue: 'Hello World', description: 'This is a test?')
        booleanParam(name: 'testBool', defaultValue: false, description: 'This is a boolean with a default value of false')
    }
    stages {
        stage('test') {
            steps {
                script {
                    echo "I'm using my parameter here: ${testString}"
                }
            }
        }
        stage('testBool') {
            when {
                expression { params.testBool == true }
            }
            steps {
                script {
                    echo "This stage was set to true"
                }
            }
        }
    }
}