Specifing git branch via a parameter

13 views
Skip to first unread message

MDKF

unread,
Aug 9, 2018, 6:45:07 PM8/9/18
to Jenkins Users
Hi All,
 I have a pipeline that starts out like this:

pipeline {
 agent any
 parameters {
        string(defaultValue: 'develop', description: 'branch', name: 'Branch')
    }
 stages {
  stage('Checkout') {
   steps {
    checkout([$class: 'GitSCM', branches: [
     [name: 'refs/remotes/origin/${params.Branch}']

When the project it runs because the parameter isn't being inserted.:
> C:\Program Files (x86)\Git\cmd\git.exe rev-parse "refs/remotes/origin/${params.Branch}^{commit}" # timeout=10
> C:\Program Files (x86)\Git\cmd\git.exe rev-parse "refs/remotes/origin/refs/remotes/origin/${params.Branch}^{commit}" # timeout=10 
> C:\Program Files (x86)\Git\cmd\git.exe rev-parse "refs/remotes/origin/${params.Branch}^{commit}" # timeout=10 

What am I doing wrong? Thanks,
-Michael

Mark Waite

unread,
Aug 9, 2018, 7:48:30 PM8/9/18
to Jenkins Users


On Thursday, August 9, 2018 at 4:45:07 PM UTC-6, MDKF wrote:
Hi All,
 I have a pipeline that starts out like this:

pipeline {
 agent any
 parameters {
        string(defaultValue: 'develop', description: 'branch', name: 'Branch')
    }
 stages {
  stage('Checkout') {
   steps {
    checkout([$class: 'GitSCM', branches: [
     [name: 'refs/remotes/origin/${params.Branch}']

String expansion in groovy happens inside a double-quoted string and does not happen inside a single-quoted string.  Change to a double-quoted string.  You may also prefer the simpler form of: 

[name: params.Branch]

Mark Waite
Reply all
Reply to author
Forward
0 new messages