Jenkins Restrict Where This Project Can Run From Properties File

Jenkins Restrict Where This Project Can Run From Properties File

jenkins pipeline restrict where this project can be run
jenkins run job on multiple nodes
jenkins-pipeline node parameter
jenkins get node label
jenkins get all nodes with label
groovy script to restrict where this project can be run
jenkins freestyle label
jenkins select build server

I want to restrict a downstream Jenkins job to run on a specific machine using a parameter passed in from an upstream job. The upstream job creates a properties file, with one of those properties indicating the machine it should run on (MACHINE_TO_RUN=linux123 in test.properties).

This file with all the properties is passed into my downstream job using Post-build Action: Trigger parameterized build on other projects. Here I specify Parameters from properties file: $WORKSPACE/test.properties

I have verified that the downstream job does indeed receive and process the file. MACHINE_TO_RUN=linux123 is listed in my environment variables.

How do I use this env variable to restrict where the job can run. I've tried setting the "Restrict where this project can be run" to ${MACHINE_TO_RUN}, but no luck.

Anyone have any experience doing this?


UPDATE: Here is how I implemented this.

Download https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Label+Assignment+plugin

Build parameters are bound with this plugin. So if you pass a cloud id or node into the job, for instance MACHINE_TO_RUN.

The plugin will let you write a groovy script that will let you return where you want the job to run.

return MACHINE_TO_RUN;


Just implemented something very much alike in the morning with NodeLabel Parameter Plugin. So, you "parametrize" the downstream job with an extra parameter of "Label" type (available only after you installed the plugin mentioned above) and provide a value for this parameter from whatever source you have (test.properties file in your case).

Also you do not have to deal with "Restrict where this project can be run" setting anymore for the downstream job.

For example, lets say you have two jobs "BUILD" and "TEST" in Jenkins with the following definitions (using Groovy-alike pseudo-code):

[TEST]
  parameters: { targetNode: typeof(Label), defaultValue: '' }

[BUILD]
  parameters: {}

  set-env-variables: { from: './test.properties' } // or your way to set env vars

  trace-env-variable: { variable: $MACHINE_TO_RUN } // linux123

  post-build: {
     trigger: {
       job: "TEST", parameters: { targetNode: $MACHINE_TO_RUN }
     }
  }

That is pretty much what you need to get the desired behavior.

jenkins, Simply i want to pass the value in "Restrict where this project can be run" field from a config file . Note-I have installed NodeLabel Parameter Plugin.Any help  After upgrading jenkins.war file from version 1.630 to 1.643, the project configuration screen does not display the "Restrict where this project can be run" setting. Most projects tied to labels before the upgrade are somehow retained - I saw in the build queue that it was waiting for available executors with the appropriate label assigned.


Node and Label parameter, If your using a node or label parameter to run your job on a particular node, you Define a label of 'Restrict where this project can be run' on the fly. to trigger the job on; fix JENKINS-15339 breaks Windows batch file build steps if Name field  Jenkins; JENKINS-61807 "restrict where this project can be run" setting missing from job configuration


I had the same problem and managed to solve it with NodeLabel Parameter Plugin.

So, In my case, I was using a multjob project to invoke a free-style project. Multi-job projects are quite good as they can run sub projects in parallel. Ensure that, you just pass the node-name parameter from the multijob and it automatically takes care that the subproject is executed in the given node. Labels are also valid node-name parameters.

In this case, I didnt have to mess with groovy.

Job Restrictions, Also can restrict job triggering by other jobs and users. Example 1: Take jobs according to the specified name pattern (e.g. allow running only "QA_.*" jobs on a Missing jelly file causes errors on job configuration pages (JENKINS-20357)  BTW "Restrict where this project can be run" requires an existing slave node or a registered label. This issue blocks loading labels from clouds, so maybe you just have no registered labels due to it Show


Jenkins Restrict Where This Project Can Run From Properties File, I want to restrict a downstream Jenkins job to run on a specific machine using a parameter passed in from an upstream job. The upstream job creates a  Jenkins UI : Read from properties File. I am trying to create a job and select Extended Choice Parameters option, where in the Parameter Type I select is Multi-Level Multi Select. It asks me for a property file. I have a normal Maven workspace , wherein I have included a certain test.properties file in the basedir of the project.


Properties, In this way, anyone in the project team can execute them in a way that leaves This plugin allows you to use Groovy script to restrict where this project can be run. properties-file (str) – file to read with properties (optional); properties-​content  Allow variable substitution for the 'Restrict where this project can be run' label expression field of the job configuration. Substitution of the form ${BRANCH} where BRANCH is a parameter to the job, will allow the job to run on any node with a label which matches BRANCH. Motivation.


How to select the correct agent to build my job? – CloudBees Support, How can we specify the agent to use to build a job? CloudBees Jenkins Enterprise - Operations Center · CloudBees Jenkins Platform - Client Master · CloudBees Jenkins Platform In a classic job type, you will find a Restrict where this project can be run checkbox and text field in the properties of the job:. Job DSL Restrict jobs to selected nodes. I want to set the property Restrict where this project can run through Access files on a node slave from Jenkins