Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2019-01-30 Thread Cristian Banarescu
Hey man! Your solution also worked for me! Thank you very much!

miercuri, 25 februarie 2015, 22:39:06 UTC+2, Victor Volle a scris:
>
> I have a partial *solution, *when I have already enabled Global 
> Properties:
>
>
> 
>
>
> the following script works for me:
>
>
> import jenkins.*
>
> import jenkins.model.*
>
> import hudson.*
>
> import hudson.model.*
>
>
> nodes = Jenkins.getInstance().getGlobalNodeProperties()
>
> nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
>
> if ( nodes.size() != 1 ) {
>
>   println("error: unexpected number of environment variable containers: "
>
>   + nodes.size()
>
>   + " expected: 1")
>
> } else {
>
>   envVars= nodes.get(0).getEnvVars()
>
>   envVars.put("FOO", "foo")
>
>   ...
>
>   Jenkins.getInstance().save()
>
>   println("okay")
>
> }
>
> I send this script to Jenkins with:
>
> java -jar /tmp/jenkins-cli.jar -s http://localhost:8080/jenkins/ groovy 
> /tmp/jenkins_global_vars.groovy
>
> and the variables are set and persisted. What I haven't yet figured out, 
> is how to enable the Global Properties in the first place
>
>

-- 
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/f77a132b-5b94-4a2a-9518-765cf00fb855%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2018-08-05 Thread Nick Mellor
the problem appears to be

hudson.slaves.EnvironmentVariablesNodeProperty.class

 passed as a parameter, but which can't be serialised.

On Monday, 6 August 2018 11:24:34 UTC+10, Nick Mellor wrote:
>
> Just to be clear: I had working code in Jenkins 2.19 that looked like this:
>
> def appVersion(String app, incrementPatch = true) {
>   assert app.toLowerCase() in ['appName'], "No such project implemented: 
> '$app'"
>   def version = [
>   elms: env.VERSION_OVERRIDE,
>   lacm: env.LACM_VERSION_OVERRIDE,
>   ].get(app.toLowerCase())
>   if (!version) {
> // auto-generate version number if no manual version given
> def nodes = Jenkins.instance.globalNodeProperties
> nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
> if (nodes.size() != 1) {
>   echo "Error: unexpected number of environment variable containers: 
> ${nodes.size()} (expected 1)"
> } else {
>   def envVars = nodes[0].envVars
>   // last patch number used is maintained per major/minor version
>   // stored in e.g. 'PATCH_VERSION_17.10' in Jenkins
>   def majorMinorVersion = env.MONTHLY_RELEASE_VERSION
>   def majorMinorPatchVar = 
> "${app.toUpperCase()}_PATCH_VERSION_${majorMinorVersion}"
>   String currentPatchVersion = envVars[majorMinorPatchVar]
>   if (currentPatchVersion) {
> if (incrementPatch) {
>   currentPatchVersion = (Integer.parseInt(currentPatchVersion) + 
> 1) as String
> }
>   } else {
> currentPatchVersion = '1'
>   }
>   // NB timestamp needs to be set statically by the pipeline
>   // to maintain version parity between pipeline stages
>   def timestamp = env.BUILD_TIMESTAMP
>   version = "$majorMinorVersion.$currentPatchVersion-$timestamp"
>   // create or update auto patch version for this major/minor build
>   // this will create new variable in Jenkins if necessary
>   envVars[majorMinorPatchVar] = currentPatchVersion
>   Jenkins.instance.save()
> }
>   }
>   echo "Autogenerated ${app.toUpperCase()} version is '$version'"
>   return version
> }
>
>
>
> Have had trouble since moving to Jenkins 2.31.
>
> Hey guys, please hold the (no doubt excellent) advice to upgrade to the 
> latest Jenkins: I'm at a large corporate that doesn't (can't, won't) move 
> quickly on Jenkins version.
>
> Thanks for any input,
>
> Nick
>
> On Monday, 6 August 2018 11:17:15 UTC+10, Nick Mellor wrote:
>>
>> Hi Zilla, this doesn't work for me. I get:
>>
>> java.io.NotSerializableException: 
>> hudson.slaves.EnvironmentVariablesNodeProperty
>>
>>
>> Any ideas?
>>
>>
>> Thanks,
>>
>>
>> Nick
>>
>>
>> On Friday, 27 July 2018 01:14:23 UTC+10, ZillaYT wrote:
>>>
>>> I just had to do this to fix it.
>>>
>>> Jenkins instance = Jenkins.getInstance()
>>> def globalNodeProperties = instance.getGlobalNodeProperties()
>>> def envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
>>> EnvironmentVariablesNodeProperty.class)
>>> def newEnvVarsNodeProperty = null
>>> def envVars = null
>>>
>>>
>>>
>>> On Thursday, July 26, 2018 at 10:52:49 AM UTC-4, ZillaYT wrote:

 I copy/pasted this code in my Jenkinsfile (including import calls 
 above) and I get

 an exception which occurred:
 in field groovy.lang.Closure.delegate
 in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@4d78782
 in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
 in object 
 org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@41f97d3f
 in object 
 org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@41f97d3f
 Caused: java.io.NotSerializableException: hudson.model.Hudson
 at 
 org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
 at 
 org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
 at 
 org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
 at 
 org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
 at 
 org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
 at 
 java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
 at 
 java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
 at java.util.HashMap.writeObject(HashMap.java:1362)
 at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
 at 
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at 
 org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
 at 
 

Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2018-08-05 Thread Nick Mellor
Just to be clear: I had working code in Jenkins 2.19 that looked like this:

def appVersion(String app, incrementPatch = true) {
  assert app.toLowerCase() in ['appName'], "No such project implemented: 
'$app'"
  def version = [
  elms: env.VERSION_OVERRIDE,
  lacm: env.LACM_VERSION_OVERRIDE,
  ].get(app.toLowerCase())
  if (!version) {
// auto-generate version number if no manual version given
def nodes = Jenkins.instance.globalNodeProperties
nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
if (nodes.size() != 1) {
  echo "Error: unexpected number of environment variable containers: 
${nodes.size()} (expected 1)"
} else {
  def envVars = nodes[0].envVars
  // last patch number used is maintained per major/minor version
  // stored in e.g. 'PATCH_VERSION_17.10' in Jenkins
  def majorMinorVersion = env.MONTHLY_RELEASE_VERSION
  def majorMinorPatchVar = 
"${app.toUpperCase()}_PATCH_VERSION_${majorMinorVersion}"
  String currentPatchVersion = envVars[majorMinorPatchVar]
  if (currentPatchVersion) {
if (incrementPatch) {
  currentPatchVersion = (Integer.parseInt(currentPatchVersion) + 1) 
as String
}
  } else {
currentPatchVersion = '1'
  }
  // NB timestamp needs to be set statically by the pipeline
  // to maintain version parity between pipeline stages
  def timestamp = env.BUILD_TIMESTAMP
  version = "$majorMinorVersion.$currentPatchVersion-$timestamp"
  // create or update auto patch version for this major/minor build
  // this will create new variable in Jenkins if necessary
  envVars[majorMinorPatchVar] = currentPatchVersion
  Jenkins.instance.save()
}
  }
  echo "Autogenerated ${app.toUpperCase()} version is '$version'"
  return version
}



Have had trouble since moving to Jenkins 2.31.

Hey guys, please hold the (no doubt excellent) advice to upgrade to the 
latest Jenkins: I'm at a large corporate that doesn't (can't, won't) move 
quickly on Jenkins version.

Thanks for any input,

Nick

On Monday, 6 August 2018 11:17:15 UTC+10, Nick Mellor wrote:
>
> Hi Zilla, this doesn't work for me. I get:
>
> java.io.NotSerializableException: 
> hudson.slaves.EnvironmentVariablesNodeProperty
>
>
> Any ideas?
>
>
> Thanks,
>
>
> Nick
>
>
> On Friday, 27 July 2018 01:14:23 UTC+10, ZillaYT wrote:
>>
>> I just had to do this to fix it.
>>
>> Jenkins instance = Jenkins.getInstance()
>> def globalNodeProperties = instance.getGlobalNodeProperties()
>> def envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
>> EnvironmentVariablesNodeProperty.class)
>> def newEnvVarsNodeProperty = null
>> def envVars = null
>>
>>
>>
>> On Thursday, July 26, 2018 at 10:52:49 AM UTC-4, ZillaYT wrote:
>>>
>>> I copy/pasted this code in my Jenkinsfile (including import calls above) 
>>> and I get
>>>
>>> an exception which occurred:
>>> in field groovy.lang.Closure.delegate
>>> in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@4d78782
>>> in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
>>> in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@41f97d3f
>>> in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@41f97d3f
>>> Caused: java.io.NotSerializableException: hudson.model.Hudson
>>> at 
>>> org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
>>> at 
>>> org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
>>> at 
>>> org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
>>> at 
>>> org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
>>> at 
>>> org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
>>> at 
>>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
>>> at 
>>> java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
>>> at java.util.HashMap.writeObject(HashMap.java:1362)
>>> at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
>>> at 
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>> at java.lang.reflect.Method.invoke(Method.java:498)
>>> at 
>>> org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
>>> at 
>>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
>>> at 
>>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
>>> at 
>>> org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
>>> at 
>>> org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
>>> at 
>>> 

Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2018-08-05 Thread Nick Mellor
Hi Zilla, this doesn't work for me. I get:

java.io.NotSerializableException: hudson.slaves.EnvironmentVariablesNodeProperty


Any ideas?


Thanks,


Nick


On Friday, 27 July 2018 01:14:23 UTC+10, ZillaYT wrote:
>
> I just had to do this to fix it.
>
> Jenkins instance = Jenkins.getInstance()
> def globalNodeProperties = instance.getGlobalNodeProperties()
> def envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
> EnvironmentVariablesNodeProperty.class)
> def newEnvVarsNodeProperty = null
> def envVars = null
>
>
>
> On Thursday, July 26, 2018 at 10:52:49 AM UTC-4, ZillaYT wrote:
>>
>> I copy/pasted this code in my Jenkinsfile (including import calls above) 
>> and I get
>>
>> an exception which occurred:
>> in field groovy.lang.Closure.delegate
>> in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@4d78782
>> in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
>> in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@41f97d3f
>> in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@41f97d3f
>> Caused: java.io.NotSerializableException: hudson.model.Hudson
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
>> at 
>> org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
>> at 
>> org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
>> at 
>> org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
>> at 
>> org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
>> at 
>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
>> at 
>> java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
>> at java.util.HashMap.writeObject(HashMap.java:1362)
>> at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
>> at 
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:498)
>> at 
>> org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
>> at 
>> org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
>> at 
>> org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
>> at 
>> org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
>> at 
>> org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
>> at 
>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
>> at 
>> com.cloudbees.groovy.cps.SerializableScript.writeObject(SerializableScript.java:26)
>> at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source)
>> at 
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:498)
>> at 
>> org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
>> at 
>> org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
>> at org.jboss.marshalling>
>>

-- 
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/83087438-a9a9-4f2f-ab89-cb16395de10c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2018-02-07 Thread Victor Volle
Which error(s)?

On Wednesday, February 7, 2018 at 11:36:50 AM UTC+1, Rakesh Bachu wrote:
>
> Hi,
> This script works fine when tested from 
> So i want to do this with a job or a pipeline
> how can i make a job or pipeline run this groovy script.
>
> i'm getting random errors when I try to run this groovy script as part of 
> a pipleline.
> Thanks,
> Rakesh
>
> On Thursday, February 26, 2015 at 3:23:27 AM UTC+5:30, Victor Volle wrote:
>>
>> Final solution:
>>
>> instance = Jenkins.getInstance()
>> globalNodeProperties = instance.getGlobalNodeProperties()
>> envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
>> EnvironmentVariablesNodeProperty.class)
>>
>> newEnvVarsNodeProperty = null
>> envVars = null
>>
>> if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 
>> 0 ) {
>>   newEnvVarsNodeProperty = new hudson.slaves.
>> EnvironmentVariablesNodeProperty();
>>   globalNodeProperties.add(newEnvVarsNodeProperty)
>>   envVars = newEnvVarsNodeProperty.getEnvVars()
>> } else {
>>   envVars = envVarsNodePropertyList.get(0).getEnvVars()
>> }
>>
>> envVars.put("FOO", "foo")
>>
>> instance.save()
>>
>>
>>
>>

-- 
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/3e177d09-e1e7-4332-8d7b-0faec69e319e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2018-02-07 Thread Rakesh Bachu
Hi,
This script works fine when tested from 
So i want to do this with a job or a pipeline
how can i make a job or pipeline run this groovy script.

i'm getting random errors when I try to run this groovy script as part of a 
pipleline.
Thanks,
Rakesh

On Thursday, February 26, 2015 at 3:23:27 AM UTC+5:30, Victor Volle wrote:
>
> Final solution:
>
> instance = Jenkins.getInstance()
> globalNodeProperties = instance.getGlobalNodeProperties()
> envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
> EnvironmentVariablesNodeProperty.class)
>
> newEnvVarsNodeProperty = null
> envVars = null
>
> if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 
> 0 ) {
>   newEnvVarsNodeProperty = new hudson.slaves.
> EnvironmentVariablesNodeProperty();
>   globalNodeProperties.add(newEnvVarsNodeProperty)
>   envVars = newEnvVarsNodeProperty.getEnvVars()
> } else {
>   envVars = envVarsNodePropertyList.get(0).getEnvVars()
> }
>
> envVars.put("FOO", "foo")
>
> instance.save()
>
>
>
>

-- 
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/80bd02c4-830e-4640-8afa-959e8034a7bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2017-11-10 Thread Josh Branham
Solved the problem, just add an envVars.clear() to the else statement 

On Thursday, November 9, 2017 at 3:58:36 PM UTC-5, Josh Branham wrote:
>
> Any idea how to make this delete all existing key pairs to ensure only the 
> ones defined in this script  are the ones in Jenkins?
>
> On Wednesday, February 25, 2015 at 4:53:27 PM UTC-5, Victor Volle wrote:
>>
>> Final solution:
>>
>> instance = Jenkins.getInstance()
>> globalNodeProperties = instance.getGlobalNodeProperties()
>> envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
>> EnvironmentVariablesNodeProperty.class)
>>
>> newEnvVarsNodeProperty = null
>> envVars = null
>>
>> if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 
>> 0 ) {
>>   newEnvVarsNodeProperty = new hudson.slaves.
>> EnvironmentVariablesNodeProperty();
>>   globalNodeProperties.add(newEnvVarsNodeProperty)
>>   envVars = newEnvVarsNodeProperty.getEnvVars()
>> } else {
>>   envVars = envVarsNodePropertyList.get(0).getEnvVars()
>> }
>>
>> envVars.put("FOO", "foo")
>>
>> instance.save()
>>
>>
>>
>>

-- 
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/90f2b3c2-8f92-4ee0-a69c-ad575d863b2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set "Environment variables" in "Global properties" of global Jenkins configuration programmatically?

2017-11-09 Thread Josh Branham
Any idea how to make this delete all existing key pairs to ensure only the 
ones defined in this script  are the ones in Jenkins?

On Wednesday, February 25, 2015 at 4:53:27 PM UTC-5, Victor Volle wrote:
>
> Final solution:
>
> instance = Jenkins.getInstance()
> globalNodeProperties = instance.getGlobalNodeProperties()
> envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
> EnvironmentVariablesNodeProperty.class)
>
> newEnvVarsNodeProperty = null
> envVars = null
>
> if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 
> 0 ) {
>   newEnvVarsNodeProperty = new hudson.slaves.
> EnvironmentVariablesNodeProperty();
>   globalNodeProperties.add(newEnvVarsNodeProperty)
>   envVars = newEnvVarsNodeProperty.getEnvVars()
> } else {
>   envVars = envVarsNodePropertyList.get(0).getEnvVars()
> }
>
> envVars.put("FOO", "foo")
>
> instance.save()
>
>
>
>

-- 
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/777d76e0-6189-42d8-97e7-6ab38c122dad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2015-02-25 Thread Victor Volle


I have a partial *solution, *when I have already enabled Global Properties:

https://lh4.googleusercontent.com/-EJJeUHpiDSs/VO4yDdXk2vI/ACY/UDR7x-oUvJo/s1600/Configure%2BSystem%2B[Jenkins]%2B2015-02-25%2B21-35-00.png


the following script works for me:


import jenkins.*

import jenkins.model.*

import hudson.*

import hudson.model.*


nodes = Jenkins.getInstance().getGlobalNodeProperties()

nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)

if ( nodes.size() != 1 ) {

  println(error: unexpected number of environment variable containers: 

  + nodes.size()

  +  expected: 1)

} else {

  envVars= nodes.get(0).getEnvVars()

  envVars.put(FOO, foo)

  ...

  Jenkins.getInstance().save()

  println(okay)

}

I send this script to Jenkins with:

java -jar /tmp/jenkins-cli.jar -s http://localhost:8080/jenkins/ groovy 
/tmp/jenkins_global_vars.groovy

and the variables are set and persisted. What I haven't yet figured out, is 
how to enable the Global Properties in the first place

-- 
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/c7f7c51a-91c4-4fe8-9847-4cd5169153d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2015-02-25 Thread Victor Volle
Final solution:

instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
EnvironmentVariablesNodeProperty.class)

newEnvVarsNodeProperty = null
envVars = null

if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 
) {
  newEnvVarsNodeProperty = new hudson.slaves.
EnvironmentVariablesNodeProperty();
  globalNodeProperties.add(newEnvVarsNodeProperty)
  envVars = newEnvVarsNodeProperty.getEnvVars()
} else {
  envVars = envVarsNodePropertyList.get(0).getEnvVars()
}

envVars.put(FOO, foo)

instance.save()



-- 
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/2fc2f1b5-3cae-4230-a1c7-30b94419f5a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2015-01-20 Thread Jonathann Zenou

I seem to have the same issue.
Does someone know what to do to alter a global variable from a job ? Is it 
even possible ?

Thanks
On Monday, September 29, 2014 at 10:17:57 AM UTC+3, mr wrote:

 Does anybody have an idea???


 Am Dienstag, 23. September 2014 12:03:51 UTC+2 schrieb mr:

 Thanks for the answer!

 Where do you inject the username and password? I think you do it into the 
 current build.

 But I want to inject a new variable or change an existing variable (like 
 e.g. username or password) into the global configuration, thus next time 
 when I go into the Global Jenkins Configuration UI, I could see the 
 username or password in the section Global properties.

 Is this possible? Is there a package like hudson.configuration.global 
 within the API which would allow me to change the environment variable 
 within the global properties jenkins configuration section?



-- 
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/8eef2f94-7794-40bf-af44-9bf17c8daefd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2014-09-29 Thread mr
Does anybody have an idea???


Am Dienstag, 23. September 2014 12:03:51 UTC+2 schrieb mr:

 Thanks for the answer!

 Where do you inject the username and password? I think you do it into the 
 current build.

 But I want to inject a new variable or change an existing variable (like 
 e.g. username or password) into the global configuration, thus next time 
 when I go into the Global Jenkins Configuration UI, I could see the 
 username or password in the section Global properties.

 Is this possible? Is there a package like hudson.configuration.global 
 within the API which would allow me to change the environment variable 
 within the global properties jenkins configuration section?


-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2014-09-23 Thread mr
Thanks for the answer!

Where do you inject the username and password? I think you do it into the 
current build.

But I want to inject a new variable or change an existing variable (like 
e.g. username or password) into the global configuration, thus next time 
when I go into the Global Jenkins Configuration UI, I could see the 
username or password in the section Global properties.

Is this possible? Is there a package like hudson.configuration.global 
within the API which would allow me to change the environment variable 
within the global properties jenkins configuration section?



Am Montag, 22. September 2014 19:48:12 UTC+2 schrieb Walter Kacynski:

 I use the following script to inject a username and password:

 usernamePassword = build.getEnvironment(null)[secret]
 def (username, password) = usernamePassword.split(':')

 e = new hudson.EnvVars()
 e.put(secret + '_USERNAME', username)
 e.put(secret + '_PASSWORD', password)
 build.environments.add(hudson.model.Environment.create(e))


 On Monday, September 22, 2014 3:23:51 AM UTC-4, mr wrote:

 Hi Folks!

 Do anybody have an idea how to set/change the variables within a Groovy 
 script?

 Regards!



-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2014-09-22 Thread mr
Hi Folks!

Do anybody have an idea how to set/change the variables within a Groovy 
script?

Regards!

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: How to set Environment variables in Global properties of global Jenkins configuration programmatically?

2014-09-22 Thread Walter Kacynski
I use the following script to inject a username and password:

usernamePassword = build.getEnvironment(null)[secret]
def (username, password) = usernamePassword.split(':')

e = new hudson.EnvVars()
e.put(secret + '_USERNAME', username)
e.put(secret + '_PASSWORD', password)
build.environments.add(hudson.model.Environment.create(e))


On Monday, September 22, 2014 3:23:51 AM UTC-4, mr wrote:

 Hi Folks!

 Do anybody have an idea how to set/change the variables within a Groovy 
 script?

 Regards!


-- 
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.
For more options, visit https://groups.google.com/d/optout.