I don't think you've read the Jenkins pipeline documentation correctly. 
String interpolation is performed by Groovy. Jenkins doesn't add any 
interpolation behavior. Jenkins will always treat single-quoted strings as 
simple literals. The "sh" step calls a shell which can do its own variable 
expansion, which is the approach recommended for passing credentials to 
external commands.

Your multi-line sh step includes calls to "mvnCommand()" and 
"jdbcUrlNoData()". Unless those are shell functions, you're unlikely to get 
the results you want.

On Tuesday, November 17, 2020 at 10:41:51 AM UTC-5 [email protected] 
wrote:

> Thanks Dirk, but that does not solve my problem, I'm still stuck.
> I think that my question boils down to why the multi-line sh command below 
> does not work?
> According to 
> https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation
> single-quoted strings should be interpolated by Jenkins (instead of using 
> Groovy string interpolation). I would assume this applies
> to both variables (e.g. GEN_USR below) and method calls returning a string 
> (e.g. jdbcUrlNoData() below)?
>
> withCredentials([usernamePassword(credentialsId: 
> 'credentialsGenerateFromDb',
>                            usernameVariable: 'GEN_USR',
>                            passwordVariable: 'GEN_PASSWD')]) {
>    String m2RepoIdentifier = "${env.BRANCH_NAME}_${env.BUILD_NUMBER}"
>
>    withEnv(javaAndMavenEnvArray()) {
>       sh '${JAVA_HOME}/bin/java -version' // single quotes - this works 
> fine!
>
>       sh script: '''
>             ${mvnCommand(m2RepoIdentifier)}\
>              -f proj-reactor/pom.xml\
>              -P GenerateStorables -DdeployAtEnd=true\
>              -Dproj.build.generatefromdb.url=${jdbcUrlNoData()}\
>              -Dproj.build.generatefromdb.user=${GEN_USR}\
>              -Dproj.build.generatefromdb.password=${GEN_PASSWD}\
>              clean ${mvnBuildGoal} pmd:pmd pmd:cpd\
>       '''
>    }
> }
>
> On Tue, Nov 17, 2020 at 2:06 PM 'Dirk Heinrichs' via Jenkins Users <
> [email protected]> wrote:
>
>> Am Dienstag, den 17.11.2020, 13:45 +0100 schrieb ST:
>>
>>  " '-Dproj.build.generatefromdb.user=${env.GEN_USR}'"
>>
>>
>> Try with ${GEN_USR} inside shell scripts, not ${env.GEN_USR}.
>>
>> HTH...
>>
>> Dirk
>>
>> -- 
>>
>> *Dirk Heinrichs*
>> Senior Systems Engineer, Delivery Pipeline
>> OpenText ™ Discovery | Recommind
>> *Phone*: +49 2226 15966 18 <+49%202226%201596618>
>> *Email*: [email protected]
>> *Website*: www.recommind.de
>> Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
>> Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, 
>> Christian Waida, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
>> This e-mail may contain confidential and/or privileged information. If 
>> you are not the intended recipient (or have received this e-mail in error) 
>> please notify the sender immediately and destroy this e-mail. Any 
>> unauthorized copying, disclosure or distribution of the material in this 
>> e-mail is strictly forbidden
>> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte 
>> Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail 
>> irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und 
>> vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte 
>> Weitergabe dieser Mail sind nicht gestattet.
>>
>> -- 
>> 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 [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-users/4dd32ea372d43c9dde0800bed9a16253d45cb2e5.camel%40opentext.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-users/4dd32ea372d43c9dde0800bed9a16253d45cb2e5.camel%40opentext.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/bed31997-28f8-4e9b-b205-43f02d4348a5n%40googlegroups.com.

Reply via email to