Re: How can I inject environment variables into my groovy class?

2017-12-02 Thread red 888
"In the pipeline there’s the global variable `env` which is a map of all 
the currently declared environment variables (JOB_NAME etc) you could pass 
into your class."

Is there a way to do that so all those envs are imported and accessible in 
the class like they are system variables? For example if I do a printenv 
from the pipeline "MyVar" shows up like its a system variable, I want it to 
show up like that from in my class too. Is there an elegant way of 
importing all the vars in "env" into my class and making them access like 
shell variables?


On Friday, December 1, 2017 at 9:08:12 AM UTC-5, Daniel Butler wrote:
>
> If you’re writing a groovy class that’s run from a library in the pipeline 
> script then you’re not going to be able to use System.getEnv().
>
>  
>
> There’s a few approaches you can take that do work:
>
>- You can pass in the values you need as parameters to the 
>methods/constructors you’re using.
>- In the pipeline there’s the global variable `env` which is a map of 
>all the currently declared environment variables (JOB_NAME etc) you could 
>pass into your class.
>- Pass in `this` from the pipeline script. You can then use this 
>object to access anything in pipeline, (Let’s assume you called the 
>field/parameter ctx) i.e. ctx.env.JOB_NAME or ctx.powershell(“write-host 
>‘spooky’”)
>
>  
>
> I noticed also you’ve got a direct execution of a process commented out, 
> don’t do that either. The same way System.getEnv() doesn’t work, doing that 
> will not behave as expected either (Assuming the sandbox will let you)
>
>  
>
>  
>
> Regards,
>
> Daniel.
>
>  
>
> *From: *red 888 
> *Sent: *29 November 2017 20:28
> *To: *Jenkins Users 
> *Subject: *Re: How can I inject environment variables into my groovy 
> class?
>
>  
>
> So this is a problem for me because the APIs I'm using in the groovy class 
> are looking for OS level environment variables.
>
>  
>
> Is there any way to set these variables with jenkins?
>
> On Tuesday, November 28, 2017 at 5:54:37 PM UTC-5, mpapo - Michael 
> Pailloncy wrote:
>
> Pipeline environment variables are not stored at the OS level. That's why 
> you are not able to get them using *System.getenv() *(which only list OS 
> level environment variables).
>
> But you should be able to retrieve them like any other classical 
> environment variables : with the "${MyVar}" syntax inside your shared lib 
> class.
>
>  
>
> Hopefully it helps.
>
>  
>
> Michaël
>
>  
>
> 2017-11-28 22:30 GMT+01:00 red 888 :
>
> My pipeline is using the environment directive to set an environment var 
> and then calls a groovy class:
>
>  
>
> def call(int blah) {
>
> pipeline {
> agent any
>
> environment {
> MyVar = credentials('djsjflsjfljsf')
> }
>
> stages {
> stage('Stage ONE') {
> steps {
> echo test.*methodA*()
>
> 
>
>  
>
>  
>
> But from in my groovy class I don't see those environment variables:
>
>  
>
> // vars/test.groovy
>
>  
>
> class test implements Serializable {
> static methodA (){
>
> def env = System.*getenv*()
> return env.dump()
> //return ['powershell', 'ls env:'].execute().text
>
> }
>
>   
>
> env.dump() and listing envs from the shell from inside the class doesn't 
> show those variables I added in the environment directive. Can I change the 
> scope of the class to give it access to these environment vars?
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
> -- 
> 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-use...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-users/87b6e2b0-ed9a-4ede-b22c-3b06761345e1%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 jenkinsci-use...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-users/6e7e1b97-7b9c-404f-9597-8577eb739b96%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

Re: Jenkins Multibranch Project Ignoring Branch That Was Deactivated Then Removed But Now We Need It Back

2017-12-02 Thread Stephen Connolly
On Sat 2 Dec 2017 at 08:37,  wrote:

> We have a Jenkins multibranch project that tracks a bunch of private
> repositories. One of the branches (development) was somehow disabled in
> Jenkins. There was a warning in the UI and the name of the branch had a
> line through it. We could not re-enable the branch so we removed the branch
> and then did a repository scan hoping it would pick it back up. I can see
> in the scan log that Jenkins finds the branch during the repo scan:
>
> Checking branch development
>
> but it takes no action on it. There's no
>
> ‘Jenkinsfile’ not found Does not meet criteria
>
> associated with it or any other feedback. It just says 'checking' and
> moves on. A Jenkinsfile exists in the branch. Just to be sure I copied one
> from a known good branch but no change. How can I get Jenkins to start
> building the branch again?
>

Do you have a filter in place? An include/exclude or regex filter should
log an ignoring message, but there may be a code path where it is not logged

Does the branch name have any funky characters in it? There are some cases
where a / can result in a query url against GitHub that will result in a
404 which might then result in this effect. We have reported that issue to
the upstream GitHub api - it may be fixed now or not yet, I haven’t checked
since it was reported


> Thanks!
>
> *This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they are
> addressed. This message contains confidential information and is intended
> only for the individual named. If you are not the named addressee you
> should not disseminate, distribute or copy this e-mail. Please notify the
> sender immediately by e-mail if you have received this e-mail by mistake
> and delete this e-mail from your system. If you are not the intended
> recipient you are notified that disclosing, copying, distributing or taking
> any action in reliance on the contents of this information is strictly
> prohibited*.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/565684ef-0ed4-4e7f-9fd9-1b7f7f6532e8%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Sent from my phone

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMzN2ju1g0SOd-nLVPCnGWmXuhTA561cOOPKJXqNNTnTeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Jenkins Multibranch Project Ignoring Branch That Was Deactivated Then Removed But Now We Need It Back

2017-12-02 Thread troym
We have a Jenkins multibranch project that tracks a bunch of private 
repositories. One of the branches (development) was somehow disabled in 
Jenkins. There was a warning in the UI and the name of the branch had a 
line through it. We could not re-enable the branch so we removed the branch 
and then did a repository scan hoping it would pick it back up. I can see 
in the scan log that Jenkins finds the branch during the repo scan:

Checking branch development

but it takes no action on it. There's no

‘Jenkinsfile’ not found Does not meet criteria

associated with it or any other feedback. It just says 'checking' and moves 
on. A Jenkinsfile exists in the branch. Just to be sure I copied one from a 
known good branch but no change. How can I get Jenkins to start building 
the branch again?

Thanks!

-- 


*This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
This message contains confidential information and is intended only for the 
individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail. Please notify the sender 
immediately by e-mail if you have received this e-mail by mistake and 
delete this e-mail from your system. If you are not the intended recipient 
you are notified that disclosing, copying, distributing or taking any 
action in reliance on the contents of this information is strictly 
prohibited*.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/565684ef-0ed4-4e7f-9fd9-1b7f7f6532e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.