Declarative pipeline: access JenkinsLocationConfiguration.getAdminAddress()?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Declarative pipeline: access JenkinsLocationConfiguration.getAdminAddress()?

Jon Dufresne
Hi,

I have several multibranch pipeline jobs that all use a declarative pipeline. The Jenkinsfiles contain the following snippet:

post {
    failure {
      step([$class: 'Mailer', recipients: '[hidden email]', sendToIndividuals: true])
    }
  }

I would like to avoid hard coding the address "[hidden email]" in all Jenkinsfiles. It is repetitive and is also incorrect when testing on a staging server or in a VM.

It occurred to me that one option could be to send to the address "JenkinsLocationConfiguration.getAdminAddress()" [0], as this is configured correctly in all scenarios listed above.

Is there an easy way to access this value from a Jenkinsfile? Is it available as some local or environment variable? A normal groovy import and method call didn't work and instead raised an exception.

If there is a better way to configure this globally, I'd consider that as well.

Cheers,
Jon

[0] http://javadoc.jenkins.io/jenkins/model/JenkinsLocationConfiguration.html#getAdminAddress()

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CADhq2b6fQBCN7NK1QUaxjg82Zm1TjZAfDi2oxRKEupDsFLM4PA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipeline: access JenkinsLocationConfiguration.getAdminAddress()?

Cuong Tran
You can access it via:

hudson.model.JenkinsLocationConfiguration.get().getAdminAddress()

You could also define a global variable on Jenkins and access it as "env.JENKINS_EMAIL".

To take it a step further, you can encapsulate the whole thing in a library using Global Shared Library plugin:


On Monday, March 20, 2017 at 2:28:12 PM UTC-7, Jon Dufresne wrote:
Hi,

I have several multibranch pipeline jobs that all use a declarative pipeline. The Jenkinsfiles contain the following snippet:

post {
    failure {
      step([$class: 'Mailer', recipients: '<a href="javascript:" target="_blank" gdf-obfuscated-mailto="EyP3uzE-CAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">c...@...', sendToIndividuals: true])
    }
  }

I would like to avoid hard coding the address "<a href="javascript:" target="_blank" gdf-obfuscated-mailto="EyP3uzE-CAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">c...@..." in all Jenkinsfiles. It is repetitive and is also incorrect when testing on a staging server or in a VM.

It occurred to me that one option could be to send to the address "JenkinsLocationConfiguration.getAdminAddress()" [0], as this is configured correctly in all scenarios listed above.

Is there an easy way to access this value from a Jenkinsfile? Is it available as some local or environment variable? A normal groovy import and method call didn't work and instead raised an exception.

If there is a better way to configure this globally, I'd consider that as well.

Cheers,
Jon

[0] <a href="http://javadoc.jenkins.io/jenkins/model/JenkinsLocationConfiguration.html#getAdminAddress()" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins.io%2Fjenkins%2Fmodel%2FJenkinsLocationConfiguration.html%23getAdminAddress()\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGJ76pb08GK-CzYU93stirDWV-e6Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins.io%2Fjenkins%2Fmodel%2FJenkinsLocationConfiguration.html%23getAdminAddress()\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGJ76pb08GK-CzYU93stirDWV-e6Q&#39;;return true;">http://javadoc.jenkins.io/jenkins/model/JenkinsLocationConfiguration.html#getAdminAddress()

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2014b1d4-e910-4f06-b26f-8bbb5a56b92e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipeline: access JenkinsLocationConfiguration.getAdminAddress()?

Jon Dufresne
Hi,

Thanks for the response. I gave this a shot. It results in the following error:

groovy.lang.MissingPropertyException: No such property: hudson for class: groovy.lang.Binding
But I think the fix is to change hudson to jenkins. So I tried this and get the following results:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.JenkinsLocationConfiguration get

So I think they is still something missing. Not sure how best to proceed. Is it not so common to access the default admin email address in a Jenkinsfiles?

On Tue, Mar 21, 2017 at 7:42 PM, Cuong Tran <[hidden email]> wrote:
You can access it via:

hudson.model.JenkinsLocationConfiguration.get().getAdminAddress()

You could also define a global variable on Jenkins and access it as "env.JENKINS_EMAIL".

To take it a step further, you can encapsulate the whole thing in a library using Global Shared Library plugin:


On Monday, March 20, 2017 at 2:28:12 PM UTC-7, Jon Dufresne wrote:
Hi,

I have several multibranch pipeline jobs that all use a declarative pipeline. The Jenkinsfiles contain the following snippet:

post {
    failure {
      step([$class: 'Mailer', recipients: '[hidden email]', sendToIndividuals: true])
    }
  }

I would like to avoid hard coding the address "[hidden email]" in all Jenkinsfiles. It is repetitive and is also incorrect when testing on a staging server or in a VM.

It occurred to me that one option could be to send to the address "JenkinsLocationConfiguration.getAdminAddress()" [0], as this is configured correctly in all scenarios listed above.

Is there an easy way to access this value from a Jenkinsfile? Is it available as some local or environment variable? A normal groovy import and method call didn't work and instead raised an exception.

If there is a better way to configure this globally, I'd consider that as well.

Cheers,
Jon

[0] http://javadoc.jenkins.io/jenkins/model/JenkinsLocationConfiguration.html#getAdminAddress()

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2014b1d4-e910-4f06-b26f-8bbb5a56b92e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CADhq2b7yL7Q%2BiJ01n3Bkk-HGXRwJGDPRsXYkBZ13PxwM1TN1rQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Declarative pipeline: access JenkinsLocationConfiguration.getAdminAddress()?

Baptiste MATHUS
I don't think it is common indeed, or at least I don't remember anything about it. You could file an issue in the tracker about it, and possibly see to propose a PR, that shouldn't be too involved I guess. It's likely to be more a matter of choosing wisely where/if to make it available.

2017-03-24 0:37 GMT+01:00 Jon Dufresne <[hidden email]>:
Hi,

Thanks for the response. I gave this a shot. It results in the following error:

groovy.lang.MissingPropertyException: No such property: hudson for class: groovy.lang.Binding
But I think the fix is to change hudson to jenkins. So I tried this and get the following results:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.JenkinsLocationConfiguration get

So I think they is still something missing. Not sure how best to proceed. Is it not so common to access the default admin email address in a Jenkinsfiles?

On Tue, Mar 21, 2017 at 7:42 PM, Cuong Tran <[hidden email]> wrote:
You can access it via:

hudson.model.JenkinsLocationConfiguration.get().getAdminAddress()

You could also define a global variable on Jenkins and access it as "env.JENKINS_EMAIL".

To take it a step further, you can encapsulate the whole thing in a library using Global Shared Library plugin:


On Monday, March 20, 2017 at 2:28:12 PM UTC-7, Jon Dufresne wrote:
Hi,

I have several multibranch pipeline jobs that all use a declarative pipeline. The Jenkinsfiles contain the following snippet:

post {
    failure {
      step([$class: 'Mailer', recipients: '[hidden email]', sendToIndividuals: true])
    }
  }

I would like to avoid hard coding the address "[hidden email]" in all Jenkinsfiles. It is repetitive and is also incorrect when testing on a staging server or in a VM.

It occurred to me that one option could be to send to the address "JenkinsLocationConfiguration.getAdminAddress()" [0], as this is configured correctly in all scenarios listed above.

Is there an easy way to access this value from a Jenkinsfile? Is it available as some local or environment variable? A normal groovy import and method call didn't work and instead raised an exception.

If there is a better way to configure this globally, I'd consider that as well.

Cheers,
Jon

[0] http://javadoc.jenkins.io/jenkins/model/JenkinsLocationConfiguration.html#getAdminAddress()

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2014b1d4-e910-4f06-b26f-8bbb5a56b92e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CADhq2b7yL7Q%2BiJ01n3Bkk-HGXRwJGDPRsXYkBZ13PxwM1TN1rQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS7mpjj2YUY0mTK8LVgUEvegdh1CcCJ-vaVLs436hndavA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...