{"id":15166102,"url":"https://github.com/jenkinsci/groovy-label-assignment-plugin","last_synced_at":"2025-03-25T17:33:30.714Z","repository":{"id":8806218,"uuid":"10502151","full_name":"jenkinsci/groovy-label-assignment-plugin","owner":"jenkinsci","description":"Jenkins plugin to set label dynamically with scripts ","archived":false,"fork":false,"pushed_at":"2019-10-09T08:14:58.000Z","size":64,"stargazers_count":1,"open_issues_count":0,"forks_count":8,"subscribers_count":102,"default_branch":"master","last_synced_at":"2025-03-20T16:39:36.193Z","etag":null,"topics":["adopt-this-plugin"],"latest_commit_sha":null,"homepage":"https://plugins.jenkins.io/groovy-label-assignment/","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jenkinsci.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-05T12:38:28.000Z","updated_at":"2023-10-17T21:02:35.000Z","dependencies_parsed_at":"2022-09-20T06:12:57.444Z","dependency_job_id":null,"html_url":"https://github.com/jenkinsci/groovy-label-assignment-plugin","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fgroovy-label-assignment-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fgroovy-label-assignment-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fgroovy-label-assignment-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fgroovy-label-assignment-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenkinsci","download_url":"https://codeload.github.com/jenkinsci/groovy-label-assignment-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245511098,"owners_count":20627318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adopt-this-plugin"],"created_at":"2024-09-27T04:41:43.525Z","updated_at":"2025-03-25T17:33:30.465Z","avatar_url":"https://github.com/jenkinsci.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Groovy Label Assignment plugin\r\n==============================\r\n\r\nJapanese version of this document is README_ja.md\r\n\r\nJenkins plugin to set label dynamically with groovy scripts\r\n\r\nWhat's this?\r\n------------\r\n\r\nGroovy Label Assignment is a [Jenkins](http://jenkins-ci.org/) plugin.\r\nThis plugin provides \"Groovy script to restrict where this project can be run\" to the job configuration page:\r\n\r\n* The value returned from the script is treated as a label expression.\r\n\t* This label expression overrides \"Restrict where this project can be run\", and \"Slaves\"/\"Label-expression\" axes of multi-configuration projects.\r\n\t* A non-string values is converted into a string with `toString()`.\r\n\t* Returning null or empty string does not override existing label expressions.\r\n* Following variables are binded to the Groovy script:\r\n\t* Parameters defined with \"This build is parameterized\".\r\n\t* Axes defined with a multi-configuration project.\r\n\t* Environment variables defined with plugins.\r\n* A build does not start (trigger is ignored) in following cases:\r\n\t* No groovy script is configured even though Groovy Label Assignment is enabled in the job.\r\n\t* The groovy script contains syntax errors.\r\n\t* The groovy script throws an exception at the runtime.\r\n\r\nUse case 1\r\n----------\r\n\r\nThink a following scenario:\r\n\r\n* You have to build a project for multiple platforms: arm, win, linux\r\n* There are following nodes:\r\n\t\r\n\t|Node|Label|arm|win|linux|\r\n\t|:---|:----|:--|:--|:----|\r\n\t|win1|vs2010,armcc|O|O|X|\r\n\t|win2|armcc|X|O|X|\r\n\t|linux|gcc|X|X|O|\r\n\r\nYou can manage this by using multi-configuration project as followings:\r\n\r\n* Define a User-defined axis \"platform\": arm, win, linux\r\n* Define a Slaves axis \"slave\": armcc, vs2010, gcc\r\n* Define \"Combination Filter\" as following:\r\n\t\r\n\t```\r\n\t(platform == \"arm\" \u0026\u0026 slave==\"armcc\") || (platform == \"win\" \u0026\u0026 slave==\"vs2010\") || (platform == \"linux\" \u0026\u0026 slave==\"gcc\")\r\n\t```\r\n\r\nGroovy Label Assignment plugin provides following alternate solution:\r\n\r\n* Define a User-defined axis \"platform\": arm, win, linux\r\n* Define \"Groovy script to restrict where this project can be run\":\r\n\t\r\n\t```\r\n\tdef labelMap = [\r\n\t    arm: \"armcc\",\r\n\t    win: \"vs2010\",\r\n\t    linux: \"gcc\",\r\n\t];\r\n\treturn labelMap.get(binding.getVariables().get(\"platform\"));\r\n\t```\r\n\r\nUse case 2\r\n----------\r\n\r\nConsider to create a job with which developers build a source tree.\r\n\r\n* You want developers can build both a release build and a snapshot with that job. Developers select release or snapshot when they trigger a build.\r\n* Release build must be built on nodes labeled \"RELEASE\" for releasing. Snapshot build must be built not on those nodes, but on other nodes.\r\n\r\nYou can create a satisfying job by using Groovy Label Assignment plugin:\r\n\r\n* Parameterize the job.\r\n* Define a Boolen Value parameter \"release\", which specifies the triggering build is for release.\r\n* Define \"Groovy script to restrict where this project can be run\":\r\n\t\r\n\t```\r\n\treturn (release == \"true\")?\"RELEASE\":\"!RELEASE\"\r\n\t```\r\n\r\nLimitations\r\n-----------\r\n\r\n* Some variables may not be properly binded:\r\n\t* Some type of parameters may be not properly binded.\r\n\t* Environment variables of some type of plugins may be not properly binded.\r\n\t* This is for Groovy Label Assignment plugin works when a build is going to be created, and is not created. Parameters and plugins that refers build information does not work properly.\r\n* When Groovy Label Assignment plugin fails, a build is rejected silently. Failures happen in following cases. You can refer the system log to see why Groovy Label Assignment plugin failed.\r\n\t* Groovy script is not defined.\r\n\t* Groovy script contains syntax errors.\r\n\t* Groovy script failed at the runtime.\r\n\t\t* Especially in case referring non-binded variables. It often happens when running with multi-configuration project. In that case, you can access the variable safely as following:\r\n\t\t\t\r\n\t\t\t```\r\n\t\t\tbinding.getVariables().get(\"variable-name\");\r\n\t\t\t```\r\n\t\t\t\r\n\t* Returned value cannot be parsed as a label expression.\r\n\r\nHow does this work?\r\n-------------------\r\n\r\nThis plugin works as following:\r\n\r\n1. When a new build is triggerd, `GroovyLabelAssignmentQueueDecisionHandler` is called.\r\n2. If `GroovyLabelAssignmentProperty` is assigned to the job, call it.\r\n3. `EnvironmentContributingAction#buildEnvVars` is called for retrieving variables to bind to the Groovy script.\r\n\t* Parameters are defined here.\r\n4. Retrieve axes values configured to that job and bind to the Groovy script.\r\n5. Run Groovy script.\r\n6. Parse returned value as a label expression.\r\n7. Assign it with `LabelAssignmentAction`.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenkinsci%2Fgroovy-label-assignment-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenkinsci%2Fgroovy-label-assignment-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenkinsci%2Fgroovy-label-assignment-plugin/lists"}