0
votes

I am using Git Parameter Plugin (0.9.12) for Jenkins declarative pipeline here as below. The output of params.branchName is master where output needs to origin/master for my case.

Is there anyway to do this ? How can I add get the origin/master output from params.brancName.

parameters {    
    gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'branchName', type: 'PT_BRANCH'
} 

stages {
    stage('Git clone and environment setup') {
        steps{
            
            git branch: "${params.branchName}", credentialsId: 'xxx', url: 'https://git.xxxx.git'

            echo 'Git paramater...' +  params.branchName
            // Git paramater...master. ->> **Which I need is origin/master**

        }
    }

    stage ('Run Tests for Dev ') {
        when {
            beforeAgent true
            expression { params.branchName == "origin/development"}
        }

Here is configuration for branches to build. Configuration

1

1 Answers

1
votes

Try this out:


parameters {
        gitParameter name: 'branchName', 
                     type: 'PT_BRANCH',
                     defaultValue: 'master'
    }

stages {
    stage('Git clone and environment setup') {
        steps{
            script {
            echo "Git paramater is ${params.branchName}"
            git branch: "${params.branchName}", credentialsId: 'xxx', url: 'https://git.xxxx.git'

            }

        }
    }

    stage ('Run Tests for Dev ') {
        when {
            beforeAgent true
            expression { "${params.branchName}" == "origin/development"}
        }
      }

I tried the same code. It worked for me:

enter image description here enter image description here