Need option to fill values in Jenkins parameterized pipeline script stored in Github whenever it run

Viewed 148

I have created a jenkins parameterized pipeline script as below. I have stored it on my Github repository.

properties([parameters([string(defaultValue: 'Devasish', description: 'Enter your name', name: 'Name'), 
                        choice(choices: ['QA', 'Dev', 'UAT', 'PROD'], description: 'Where you want to deploy?', name: 'Environnment')])])

pipeline {
    agent any

    stages {
        stage('one') {
            steps {
                echo "Hello ${Name} Your code is Building in ${Environnment} "
            }
        }
        stage('Two') {
            steps {
                echo "Hello ${Name} hard testing in  ${Environnment}"
            }
        }
        stage('Three') {
            steps {
                echo "Hello1 ${Name} deploying in  ${Environnment}"
            }
        }
    }
}

Then, I have created a jenkins job by choosing pipeline option. While creating jenkins pipeline Under build triggers section, I have checked GitHub hook trigger for GITScm polling checkbox and Under Pipeline section, I have chosen Pipeline script from SCM followed by choosing Git in SCM, providing Repository URL where the above written JenkinsFile script is stored.

Then, Under Github repository settings, I have gone to webhooks and added one webhook where I specified my Payload URL as myJenkinsServerURL/github-webhook/. which will enable a functionality like whenever there will be any push event occurred within the repository, it will run the jenkins pipeline I created above.

Now, the situation is, when I am running this jenkins job from Classic UI by clicking Build with parameters, I am getting a text box to fill my name and a dropdown having list of 4 options ('QA', 'Dev', 'UAT', 'PROD') I gave above in script to choose, in which server I want to deploy my code, then it gets run.

But when I am committing in Github, it starts jenkins pipeline but not asking for parameters value instead just taking default value Devasish in name and QA in server.

What should I do to get an option of filling these details but not from Classic UI.

Thanks in advance.

1 Answers

As you have noted, when you trigger your pipeline manually, it will ask for the Build Parameters and let you specify values before proceeding. However, when triggering the pipeline thru automatic triggers (e.g. SCM triggers/webhooks), then it is assumed to be an unattended build and it will use the defaultValue settings from your Jenkinsfile build parameters" definition.

Related