Re: Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-11-16 Thread chowhan . adi
Hi All 
>
> i am also trying to achieve the similar thing where will be passing the 
parameters as string in Jenkins so  In the above solution tried to modify 
to my requirement as i wanted to add "new SSHLauncher("172.17.1.55",22,
"root","root","","","","",""),"
but it fails to find the class could some share your thoughts

Thanks in advance 
Aditya

/**
 * This script is meant to be executed by a parameterized job in Jenkins 
and will then create new agents (slaves) as per the parameters
 *
 * SUGGESTED PAIRED PARAMETERS IN JENKINS (type, name, default values, 
description):
 *
 * Text - AgentList - "TestAutoAgent" - Name of agents to create, 
optionally more than one (each line makes one agent)
 * String - AgentDescription - "Auto-created Jenkins agent" - Description 
that'll be set for _every_ created agent
 * String - AgentHome - "D:\JenkinsAgent" - Remote filesystem root for the 
agent
 * String - AgentExecutors - 2 - Number of executors for the agent
 */

import hudson.model.Node.Mode
import hudson.slaves.*
import jenkins.model.Jenkins
import hudson.plugins.sshslaves.*
import java.util.List;
/*
//Handy debug logging
Jenkins.instance.nodes.each {
println "BEFORE - Agent: $it"
}
*/

// The "build" object is added by the Jenkins Groovy plugin and can resolve 
parameters and such
String agentList = build.buildVariableResolver.resolve('AgentList')
String agentDescription = 
build.buildVariableResolver.resolve('AgentDescription')
String agentHome = build.buildVariableResolver.resolve('AgentHome')
String agentExecutors = 
build.buildVariableResolver.resolve('AgentExecutors')

agentList.eachLine {

// There is a constructor that also takes a list of properties (env 
vars) at the end, but haven't needed that yet
DumbSlave dumb = new DumbSlave(it,  // Agent name, usually matches the 
host computer's machine name
agentDescription,   // Agent description
agentHome,  // Workspace on the agent's computer
agentExecutors, // Number of executors
Mode.NORMAL,// "Usage" field, EXCLUSIVE is 
"only tied to node", NORMAL is "any"
"", // Labels
new SSHLauncher(),
RetentionStrategy.INSTANCE) // Is the "Availability" field and 
INSTANCE means "Always"

Jenkins.instance.addNode(dumb)
println "Agent '$it' created with $agentExecutors executors and home 
'$agentHome'"
}

/*
Jenkins.instance.nodes.each {
println "AFTER - Agent: $it"
}
*/

-- 
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/7f31cf34-a941-4e57-9c67-84d6f691e996%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-10-05 Thread Amit Ghatwal
on which extends 
>> jobRestriction so this class is a subclass of JobRestriction.
>> You need to instantiate a new StartedByUserRestriction class giving it : 
>>  (list of UserSelector, false, false, false).  <==  I presume you just want 
>> the list of users able to run job on the node, with no Upstream Job started 
>> by user or AutoRun or started by Anonymous User.
>>
>> 3. You pass in “StartedByUserRestriction" class created when you 
>> instantiate the new “JobRestrictionProperty" class.
>>
>> 4. Then you create a new LinkList and you add the JobRestrictionProperty 
>> class instance to the List.
>>
>> 5. You pass in the LinkList as the last parameter to the creation of the 
>> new DumbSlave class to create new node/Agent (see nodeProperties below):
>>
>> http://javadoc.jenkins-ci.org/hudson/slaves/DumbSlave.html
>>
>> public DumbSlave(String 
>> <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
>>  name,
>>  String 
>> <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
>>  nodeDescription,
>>  String 
>> <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
>>  remoteFS,
>>  String 
>> <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
>>  numExecutors,
>>  Node.Mode 
>> <http://javadoc.jenkins-ci.org/hudson/model/Node.Mode.html> mode,
>>  String 
>> <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
>>  labelString,
>>  ComputerLauncher 
>> <http://javadoc.jenkins-ci.org/hudson/slaves/ComputerLauncher.html> launcher,
>>  RetentionStrategy 
>> <http://javadoc.jenkins-ci.org/hudson/slaves/RetentionStrategy.html> 
>> retentionStrategy,
>>  *List 
>> <http://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true>>  extends NodeProperty 
>> <http://javadoc.jenkins-ci.org/hudson/slaves/NodeProperty.html>> 
>> nodeProperties)*
>>   throws IOException 
>> <http://docs.oracle.com/javase/7/docs/api/java/io/IOException.html?is-external=true>,
>>  Descriptor.FormException 
>> <http://javadoc.jenkins-ci.org/hudson/model/Descriptor.FormException.html>
>>
>>
>>
>>
>> From: <jenkins...@googlegroups.com> on behalf of Amit Ghatwal <
>> ghatw...@gmail.com>
>> Reply-To: "jenkins...@googlegroups.com" <jenkins...@googlegroups.com>
>> Date: Tuesday, October 4, 2016 at 9:25 PM
>> To: Jenkins Users <jenkins...@googlegroups.com>
>> Subject: Re: Creating groovy script to configure slave node properties 
>> >> "Restrict jobs execution at node"
>>
>> Hi Victor,
>>
>> Thanks for quick comment.
>> I had already looked at the below repo of "job-restriction plugin" - 
>> https://github.com/jenkinsci/job-restrictions-plugin/tree/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions
>>
>> However i am unable to figure how do i change the slave node >>  
>> configure >> Node Properties >> Restrict jobs execution at node via a 
>> groovy script ?
>> Any pointers on how can i bring out the above change might be helpful.
>>
>> Thanks and regards,
>> Amit
>>
>> On Tuesday, 4 October 2016 22:24:47 UTC+5:30, Victor Martinez wrote: 
>>>
>>> You might need to look at the job resctriciton plugin to find its jobs 
>>> properties and create that property: 
>>>
>>>
>>> https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java
>>>
>>> The above url might help you to understand what that plugin does
>>>
>>> Cheers 
>>>
>>> -- 
>> 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/3d03feac-510c-4ba2-987c-76e50b7a1f38%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-users/3d03feac-510c-4ba2-987c-76e50b7a1f38%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> 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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/b4503607-e3fa-4de0-ba79-6da54bca2548%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-10-05 Thread Amit Ghatwal
va/util/List.html?is-external=true>  extends NodeProperty 
> <http://javadoc.jenkins-ci.org/hudson/slaves/NodeProperty.html>> 
> nodeProperties)*
>   throws IOException 
> <http://docs.oracle.com/javase/7/docs/api/java/io/IOException.html?is-external=true>,
>      Descriptor.FormException 
> <http://javadoc.jenkins-ci.org/hudson/model/Descriptor.FormException.html>
>
>
>
>
> From: <jenkins...@googlegroups.com > on behalf of Amit 
> Ghatwal <ghatw...@gmail.com >
> Reply-To: "jenkins...@googlegroups.com " <
> jenkins...@googlegroups.com >
> Date: Tuesday, October 4, 2016 at 9:25 PM
> To: Jenkins Users <jenkins...@googlegroups.com >
> Subject: Re: Creating groovy script to configure slave node properties >> 
> "Restrict jobs execution at node"
>
> Hi Victor,
>
> Thanks for quick comment.
> I had already looked at the below repo of "job-restriction plugin" - 
> https://github.com/jenkinsci/job-restrictions-plugin/tree/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions
>
> However i am unable to figure how do i change the slave node >>  configure 
> >> Node Properties >> Restrict jobs execution at node via a groovy script ?
> Any pointers on how can i bring out the above change might be helpful.
>
> Thanks and regards,
> Amit
>
> On Tuesday, 4 October 2016 22:24:47 UTC+5:30, Victor Martinez wrote: 
>>
>> You might need to look at the job resctriciton plugin to find its jobs 
>> properties and create that property: 
>>
>>
>> https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java
>>
>> The above url might help you to understand what that plugin does
>>
>> Cheers 
>>
>> -- 
> 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/3d03feac-510c-4ba2-987c-76e50b7a1f38%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-users/3d03feac-510c-4ba2-987c-76e50b7a1f38%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/55cca636-4217-4145-b201-b30db8d83d34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-10-04 Thread Indra Gunawan (ingunawa)
Hi Amit,

The 
https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java
 class clearly extends NodeProperty.
1. You need to instantiate a new JobRestrictionProperty class giving to it a 
new instance of jobRestriction class.

2. You are saying you want to Restrict jobs execution at node just for User?   
Do you want to configure "Started by User"?
I assume you do, therefore you then browse to 
https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/job/StartedByUserRestriction.java
This class extends AbstractUserCauseRestriction which extends jobRestriction so 
this class is a subclass of JobRestriction.
You need to instantiate a new StartedByUserRestriction class giving it :  (list 
of UserSelector, false, false, false).  <==  I presume you just want the list 
of users able to run job on the node, with no Upstream Job started by user or 
AutoRun or started by Anonymous User.

3. You pass in "StartedByUserRestriction" class created when you instantiate 
the new "JobRestrictionProperty" class.

4. Then you create a new LinkList and you add the JobRestrictionProperty class 
instance to the List.

5. You pass in the LinkList as the last parameter to the creation of the new 
DumbSlave class to create new node/Agent (see nodeProperties below):

http://javadoc.jenkins-ci.org/hudson/slaves/DumbSlave.html

public 
DumbSlave(String<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
 name,
 
String<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
 nodeDescription,
 
String<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
 remoteFS,
 
String<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
 numExecutors,
 Node.Mode<http://javadoc.jenkins-ci.org/hudson/model/Node.Mode.html> 
mode,
 
String<http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true>
 labelString,
 
ComputerLauncher<http://javadoc.jenkins-ci.org/hudson/slaves/ComputerLauncher.html>
 launcher,
 
RetentionStrategy<http://javadoc.jenkins-ci.org/hudson/slaves/RetentionStrategy.html>
 retentionStrategy,
 
List<http://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true>http://javadoc.jenkins-ci.org/hudson/slaves/NodeProperty.html>> 
nodeProperties)
  throws 
IOException<http://docs.oracle.com/javase/7/docs/api/java/io/IOException.html?is-external=true>,
 
Descriptor.FormException<http://javadoc.jenkins-ci.org/hudson/model/Descriptor.FormException.html>



From: 
<jenkinsci-users@googlegroups.com<mailto:jenkinsci-users@googlegroups.com>> on 
behalf of Amit Ghatwal <ghatwala...@gmail.com<mailto:ghatwala...@gmail.com>>
Reply-To: 
"jenkinsci-users@googlegroups.com<mailto:jenkinsci-users@googlegroups.com>" 
<jenkinsci-users@googlegroups.com<mailto:jenkinsci-users@googlegroups.com>>
Date: Tuesday, October 4, 2016 at 9:25 PM
To: Jenkins Users 
<jenkinsci-users@googlegroups.com<mailto:jenkinsci-users@googlegroups.com>>
Subject: Re: Creating groovy script to configure slave node properties >> 
"Restrict jobs execution at node"

Hi Victor,

Thanks for quick comment.
I had already looked at the below repo of "job-restriction plugin" - 
https://github.com/jenkinsci/job-restrictions-plugin/tree/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions

However i am unable to figure how do i change the slave node >>  configure >> 
Node Properties >> Restrict jobs execution at node via a groovy script ?
Any pointers on how can i bring out the above change might be helpful.

Thanks and regards,
Amit

On Tuesday, 4 October 2016 22:24:47 UTC+5:30, Victor Martinez wrote:
You might need to look at the job resctriciton plugin to find its jobs 
properties and create that property:

https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java

The above url might help you to understand what that plugin does

Cheers

--
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<mailto:jenkinsci-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/3d03feac-510c-4ba2-987c-76e50b7a1f38%40googlegroups.com<https://groups.google.com/d/msgid/jenkinsci-users/3d03f

Re: Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-10-04 Thread Amit Ghatwal
Hi Victor,

Thanks for quick comment.
I had already looked at the below repo of "job-restriction plugin" - 
https://github.com/jenkinsci/job-restrictions-plugin/tree/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions

However i am unable to figure how do i change the slave node >>  configure 
>> Node Properties >> Restrict jobs execution at node via a groovy script ?
Any pointers on how can i bring out the above change might be helpful.

Thanks and regards,
Amit

On Tuesday, 4 October 2016 22:24:47 UTC+5:30, Victor Martinez wrote:
>
> You might need to look at the job resctriciton plugin to find its jobs 
> properties and create that property:
>
>
> https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java
>
> The above url might help you to understand what that plugin does
>
> Cheers 
>
>

-- 
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/3d03feac-510c-4ba2-987c-76e50b7a1f38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-10-04 Thread Victor Martinez
You might need to look at the job resctriciton plugin to find its jobs 
properties and create that property:

https://github.com/jenkinsci/job-restrictions-plugin/blob/master/src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/nodes/JobRestrictionProperty.java

The above url might help you to understand what that plugin does

Cheers 

-- 
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/22f5a3c3-7d20-41d6-aefb-bb7e963e61c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Creating groovy script to configure slave node properties >> "Restrict jobs execution at node"

2016-10-03 Thread Amit Ghatwal

Hi All,

I am trying to automate the process of creating a slave node on jenkins 
server , creating users and then and also allow certain users to access 
only certain slave nodes. The automation is to be achieved via a groovy 
script.

Here's my script thus far
import jenkins.model.* 
import hudson.security.* 
import hudson.slaves.*
import hudson.plugins.sshslaves.*
import hudson.model.*


SLAVE_IP_ADDR="172.17.1.55"
SLAVE_LOGIN="root"
SLAVE_PWD="root"

SLAVE_NODE_LABEL="My_Slave_Node_Autogenerated-Label"


println "create a slave node.. \n\r"
Slave slave_node = new DumbSlave( 
"My_Slave_Node_Autogenerated",
"This slave node is generated using a jenkins job via groovy script",
"/home/jenkins",
"1",
Node.Mode.NORMAL,
SLAVE_NODE_LABEL,
new SSHLauncher(SLAVE_IP_ADDR,22,SLAVE_LOGIN,SLAVE_PWD,"","","","",""),
new RetentionStrategy.Always(),
new LinkedList()
)
Jenkins.instance.addNode(slave_node)



So doing above , i am able to achieve creation of slave nodes, now what i 
want to do is to restrict the users created ( done by a groovy script too ) 
to have restricted access to the slave nodes created above. For this we 
need "job-restriction" plugin installed. I have version 0.5 installed on my 
server. Post installation of the plugin ,i have " Restrict jobs execution 
at node " option seen under " Node properties " for any slave node 
configure setting.

Now i can manually on the jenkins UI , i am able to achieve restriction of 
users created for any slave node , however do i get this automated using a 
groovy script.

Any thought how "Restrict jobs execution at node " can be achieved using a 
groovy script ? Any pointers will be helpful

Thanks and regards,
Amit

I

-- 
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/82077b14-66ad-4a86-8887-dd1113197c31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.