Hi Indra ,

You've have hit the nail on its head , you have perfectly summarized my 
requirements and precisely what i intent to achieve via a groovy script.

import jenkins.model.*
import hudson.model.*
import hudson.slaves.*
import hudson.plugins.sshslaves.*
import java.util.ArrayList;
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry;


import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.nodes.
JobRestrictionProperty; 

import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.Messages;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.
JobRestriction;
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.
JobRestrictionBlockageCause;
import hudson.Extension;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.queue.CauseOfBlockage;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;

  List<Entry> env = new ArrayList<Entry>();
  env.add(new Entry("key1","value1"))
  env.add(new Entry("key2","value2"))
  EnvironmentVariablesNodeProperty envPro = new 
EnvironmentVariablesNodeProperty(env);
  Slave slave = new DumbSlave(
                    "agent-node","Agent node description",
                    "/home/jenkins",
                    "1",
                    Node.Mode.NORMAL,
                    "agent-node-label",
                    new SSHLauncher("agenNode",22,"user","password","","",""
,"",""),
                    new RetentionStrategy.Always(),
                    new LinkedList())
  slave.getNodeProperties().add(envPro)
  Jenkins.instance.addNode(slave)

I am actually kind of new to "groovy" , if u don't mind , as referred by 
you in above points : 1,2,3,4,5 is perfectly what i need , but if you could 
help in editing above groovy code to incorporate the points 1-5 as 
mentioned by you would be helpful.

Appreciate your time and help.
Thanks and regards,
Amit

On Wednesday, 5 October 2016 11:12:23 UTC+5:30, Indra Gunawan (ingunawa) 
wrote:
>
> 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<Node>.
> 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><?
>  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: <[email protected] <javascript:>> on behalf of Amit 
> Ghatwal <[email protected] <javascript:>>
> Reply-To: "[email protected] <javascript:>" <
> [email protected] <javascript:>>
> Date: Tuesday, October 4, 2016 at 9:25 PM
> To: Jenkins Users <[email protected] <javascript:>>
> 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 [email protected] <javascript:>.
> 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&utm_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 [email protected].
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.

Reply via email to