2

I am trying to use jgitflow plugin for maven and run a release via Jenkins pipeline.

Plugin configuration:

<plugin>
     <groupId>external.atlassian.jgitflow</groupId>
     <artifactId>jgitflow-maven-plugin</artifactId>
     <version>1.0-m5.1</version>
     <configuration>
        <username>${git.user}</username>
        <password>${git.password}</password>
        <enableSshAgent>true</enableSshAgent>
        <autoVersionSubmodules>true</autoVersionSubmodules>
        <noDeploy>true</noDeploy>
        <releaseBranchVersionSuffix>-RELEASE</releaseBranchVersionSuffix>
     </configuration>
</plugin>

The problem is when I am passing a credentials for jgitflow.

withCredentials([usernamePassword(credentialsId: 'my_credentials_id', passwordVariable: 'USERNAME', usernameVariable: 'PASSWORD')]) {
    sh "git checkout develop"
    sh "mvn -f jgitflow:release-start -B -U -DskipTests -DnoDeploy=true -DpushReleases=false -Dgit.user=$USERNAME -Dgit.password=$PASSWORD"
    sh "mvn -f jgitflow:release-finish -B -U -Dmaven.javadoc.skip=true -DskipTests -DnoDeploy=true -DpushReleases=true -Dgit.user=$USERNAME -Dgit.password=$PASSWORD"
 }

Settings above don't work, but everything is fine if I pass username and password explicitly instead of by variable. Am I using it wrong?

staszko032
  • 802
  • 6
  • 16
  • how did you generate your pipeline script for credentials? – Sagar Apr 26 '18 at 10:51
  • With usage of "Pipeline syntax" page of Jenkins. I have tried to call an `echo "$USERNAME"` and it gives me an masked form of username, so I assume the syntax is correct. – staszko032 Apr 26 '18 at 10:55
  • 1
    can you try to add follow this syntax: `withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']])` – Sagar Apr 26 '18 at 11:03
  • It works, thank you. I have to read more about credentials bindings. – staszko032 Apr 26 '18 at 11:11
  • Great! I will update it as answer. Help me to approve so that others can benefit too – Sagar Apr 26 '18 at 11:12

1 Answers1

4

In some cases, the output generated by the pipeline script is tricky cannot be used as it is. Use following code to access the credentials:

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '<CREDENTIAL_ID>', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']])

instead of generated code.

Sagar
  • 23,903
  • 4
  • 62
  • 62