jenkinsci / azure-cli-plugin

A Jenkins plugin to use Azure CLI for managing Azure resources.
https://plugins.jenkins.io/azure-cli/
MIT License
5 stars 18 forks source link

Environment Vars not being set #11

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,

I'm trying to use the exportVariablesString as part of a query to make my pipeline simpler, but I am unable to get the environment variable to work.

Pipeline:

azureCLI commands: [[exportVariablesString: '/ipAddress|PUBLIC_IP', script: 'az network public-ip show ...
sh "echo ${PUBLIC_IP}"

Output:

Transforming to environment variables: /ipAddress|PUBLIC_IP
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: PUBLIC_IP for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
    at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:284)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:288)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:264)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:264)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at WorkflowScript.run(WorkflowScript:9)

I would love to get this working to clean up my Jenkinsfile

torosent commented 6 years ago

I will check.

torosent commented 6 years ago

Fixed with 0.9

node {
    azureCLI commands: [[exportVariablesString: '/ipAddress|PUBLIC_IP', script: 'az network public-ip show --resource-group test -n pip']], principalCredentialId: 'superSecretCredential'
    sh "echo ${PUBLIC_IP}"
}
jcmmv00 commented 4 years ago

It doesn't work at 0.9, I still have the error, the variable is empty

azureCLI commands: [[exportVariablesString: '/ipAddress|PUBLIC_IP', script: 'az container show --name --resource-group ']], principalCredentialId: 'serviceJenkinsPrincipal' sh "echo ${PUBLIC_IP}"

Transforming to environment variables: /ipAddress|PUBLIC_IP [Pipeline] sh

[Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS

jcmmv00 commented 4 years ago

The real reason that the PUBLIC_IP variable is empty is because the JSON path is not valid or is another JSON object.

this example works for me, (pay atention on exportVariablesString = "/ipAddress/ip|PUBLIC_IP'"):

azureCLI commands: [[exportVariablesString: '/ipAddress/ip|PUBLIC_IP', script: 'az container show --name --resource-group ']], principalCredentialId: 'serviceJenkinsPrincipal'

sh "echo ${PUBLIC_IP}"