jenkinsci / jenkinsci/configuration-as-code-plugin

Combine node specific labels with common labels.

Open
#1,529 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
2.8k
Forks
756
Avg merge
9h 47m
Merged PRs (30d)
10

Description

### Your checklist for this issue

🚨 Please review the [guidelines for contributing](../blob/master/docs/CONTRIBUTING.md) to this repository.

- [x] Link to any upstream changes that might be required (for example Jenkins Core pull request)

### Feature Request

I explained the problem on [StackOverflow](https://stackoverflow.com/questions/64720193/jcasc-is-there-a-way-to-combine-node-specific-labels-with-common-labels), but I'll repeat it here:

Below is an example of what our current configuration looks like:

```
x-node-defaults: &node-defaults
labelString: "common-label-1 common-label-2 common-label-3"

jenkins:
nodes:
- permanent:
name: "node-1"
<<: *node-defaults
- permanent:
name: "node-2"
<<: *node-defaults
labelString: "common-label-1 common-label-2 common-label-3 node-specific-1"
```

Our actual configuration has a lot more nodes and a lot more properties configured, but this shows the problem we are having: ___We can't add node specific labels without duplicating all the common labels.___

I haven't been able to find a YAML way of concatenating strings, and while you can't exactly merge arrays in YAML, you almost can: You can make arrays of arrays. To get from an array of arrays to a label string, all you have to do is flatten the array and join the elements with space as separator. Here's an example from [StackOverflow](https://stackoverflow.com/a/57209078/310121):

```
.pip_git: &pip_git
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com".insteadOf "ssh://git@gitlab.com"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts

test:
image: python:3.7.3
stage: test
script:
- *pip_git
- pip install -q -r requirements_test.txt
- python -m unittest discover tests
```

This makes `script` an array of arrays:

```
[["git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com\".insteadOf \"ssh://git@gitlab.com\"",
"mkdir -p ~/.ssh",
"chmod 700 ~/.ssh",
"echo \"$SSH_KNOWN_HOSTS\" > ~/.ssh/known_hosts",
"chmod 644 ~/.ssh/known_hosts"],
"pip install -q -r requirements_test.txt",
"python -m unittest discover tests"]
```

I was thinking that in addition to `labelString`, we could have a `labels` property which is an array of strings. Internally, we will flatten, join and merge it with the `labelString`. That way, it will be backwards compatible and easy to use.

I'm not too familiar with the architecture of JCasC, so I don't know how feasible my proposal is, or where it should be implemented. The implementation itself should be trivial, just need to know where to put it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.