1

I am trying to parameterize a Jenkins pipeline. The only input parameter will be GITHUB_URL. I have a Jenkinsfile as a part of the repo. I want to use this variable (defined as parameter) in my pipeline configuration as "Repository URL". How can I access the parameter ?

I have tried $GITHUB_URL, ${GITHUB_URL} and ${params.GITHUB_URL}. No luck

Any other suggestions?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Ramprasad V
  • 347
  • 1
  • 5
  • 16

1 Answers1

2

Because you are telling you have a jenkinsfile inside your git repo I suppose you do not mean that you want to call a Jenkinsfile using parameters from a shared library.

It's also not sure if you are using a declarative or scripted pipeline. I will explain the "recommended" declarative pipeline:

pipeline {
    agent any


    parameters { 
        string(defaultValue: "https://github.com", description: 'Whats the github URL?', name: 'URL')
    }


    stages {
        stage('Checkout Git repository') {
           steps {
                git branch: 'master', url: "${params.URL}"
            }
        }

        stage('echo') {
           steps {
                echo "${params.URL}"
            }
        }
    }
}

In this pipeline you will add a string parameter to which you can add a URL. When you run the build it will ask for the parameter: enter image description here

To use this parameter use "${params.URL}": This pipeline will clone the github repo in the first stage and print the URL in the next (echo) stage:

[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (echo)
[Pipeline] echo
https://github.com/lvthillo/docker-ghost-mysql.git
[Pipeline] }
lvthillo
  • 28,263
  • 13
  • 94
  • 127
  • Thanks a lot for your answer lvthillo. I am using a scripted pipeline. The Jenkinsfile is a part of the repo https://github.com/vrprasad/sample.git. All I want to do is give this URL as parameter, and Jenkinsfile should be fetched from this. – Ramprasad V Feb 02 '18 at 11:29