0

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 Answers1

0

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"
                }
            }
        }
    }
}
BenCourliss
  • 497
  • 5
  • 13
  • Hi friend, thank you for your comment. But I can't use this declarative pipeline. I have already used this, but not able to create parameters with this as well. I don't know why. May be my organisation has restricted some of the settings, this is reason or not. When we run Jenkins job, i remember, Jenkinsfile file runs first. So with that, we can create parameters. But the Jenkins which I am using now, i checked console output, but I don't see Jenkinsfile is ruining. – Karan Kambli Feb 22 '23 at 11:19
  • In the very beginning you can see which file jenkins is actually running. – Holleoman Mar 13 '23 at 20:32
  • You can use the environment variable to set parameters. – Holleoman Mar 13 '23 at 20:32