[Declarative Pipeline] params.xxx does not work for git

46 views
Skip to first unread message

Dan Tran

unread,
Jan 4, 2017, 1:41:30 AM1/4/17
to Jenkins Users
I am trying to create pipe where user can enter their own git url and branch

pipeline {

    agent any

    parameters {
        stringParam(defaultValue: 'ssh://xxxx/yyyy/zzz.git', description: '', name: 'gitUrl')
        stringParam(defaultValue: 'master', description: '', name: 'gitBranch')
    }

    properties {
        buildDiscarder(logRotator(numToKeepStr:'2'))
        disableConcurrentBuilds()
    }

    stages {

        stage ('checkout') {
            steps {
              git url: '${params.gitUrl}', branch: '${params.branch}'
            }
        }

    }
}


here is the error

> git fetch --tags --progress ${params.gitUrl} +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from ${params.gitUrl}
 
I can file a bug if it is confirm

Thanks

-Dan


Dan Tran

unread,
Jan 4, 2017, 1:46:09 AM1/4/17
to Jenkins Users

false alarm again, i need to double quote.  Not sure if this is intended

  git url: "${params.gitUrl}", branch: "${params.branch}"

Daniel Beck

unread,
Jan 4, 2017, 2:45:09 AM1/4/17
to jenkins...@googlegroups.com

> On 04.01.2017, at 07:46, Dan Tran <dan...@gmail.com> wrote:
>
> git url: "${params.gitUrl}", branch: "${params.branch}"

Or just `git url: params.gitUrl, branch: params.branch`

Double quoted strings are interpolated strings, single quoted strings are not. The same in Groovy (Pipeline DSL) as in Perl, PHP, bash, …

Dan Tran

unread,
Jan 4, 2017, 3:02:06 AM1/4/17
to Jenkins Users, m...@beckweb.net
Thanks,  the venture into pipeline, groovy, and declarative pipeline are interesting.  Take some hands on to get a hang of it

-Dan

David Karr

unread,
Jan 4, 2017, 3:56:13 PM1/4/17
to jenkins...@googlegroups.com
On Tue, Jan 3, 2017 at 10:46 PM, Dan Tran <dan...@gmail.com> wrote:
> false alarm again, i need to double quote. Not sure if this is intended
>
> git url: "${params.gitUrl}", branch: "${params.branch}"

That's a Groovy restriction. A single-quoted string is only a
"string", but a double-quoted string is a "gstring", which does
parameter interpolation.

Baptiste Mathus

unread,
Jan 12, 2017, 3:01:47 AM1/12/17
to jenkins...@googlegroups.com
Nitpicking, I would argue it is not a "restriction" but a feature.
BTW this is a common behaviour: exactly the same exists in shell for instance, and I'm sure in other languages.

A feature because it's nice to not always have to add antislashes for parameters/variables you don't want resolved by the pipeline code itself.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAA5t8VoVWXOKxhJyJCsh7gqC2bvoTxyZF117WAjp9-9LJBbybw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages