2

I have a working set of JJB YAML files successfully creating jobs and folders.

I now want to make certain values I use inside those YAML files configurable i.e. when running jenkins-jobs test|update -r jobfolder I want to set values for folder prefixes (to not damage existing production jobs), names for branches, nodes etc.

I don't want to use JJBs defaults approach for this since I'm already using it for configuration at a different place and it results in conflicts when used in projects and jobs together.

The ideal way of doing this I can think of would be a way to call JJB like this

jenkins-jobs test|update --define "folder-prefix=experimental/,node=test-node" -r jobfolder

Giving me variables I can use in the actual job definition files.

Since this option seemingly doesn't exist, I'm currently trying to provide files which contain those variables and somehow 'inject' them in my project.

Those are the approaches I can think of:

1 - having different configuration folders with YAML files inside, I would use like this:

jenkins-jobs test -r experimental-config:jobfolder 
jenkins-jobs test -r production-config:jobfolder 

with experimental-config and production-config being folders with additional files containing my configuration I can switch between.

But unfortunately I don't know how I would reference values I've defined in different yaml files. Is that even possible?

2 - having include files like described in the documentation

While that sounds promising I didn't manage to actually make this run. I tried to turn the following 'configuration header' I'm already using:

- dynamic-config: &dynamic-config
    name: "dynamic-config"
    folder-prefix: "experimental/"
    node: "test-node"

[Rest of the file making use of dynamic-config]

into something making use of the !include statement like this:

!include: dynamic-config.yaml.inc

[Rest of the file making use of stuff defined in dynamic-config.yaml.inc]

giving me a seemingly unrelated parser error:

yaml.parser.ParserError: expected '<document start>', but found '<block sequence start>'
  in "/home/me/my/project.yml", line 11, column 1

so I tried this snippet, which looks more like the example by putting it inside an existing element:

- dynamic-config: &dynamic-config
    name: "dynamic-config"
    !include: dynamic-config.yaml.inc

giving me a different error but still an error:

yaml.scanner.ScannerError: while scanning a simple key
  in "/home/me/my/project.yml", line 7, column 5
could not find expected ':'
  in "/home/me/my/project.yml", line 8, column 5

In both cases it doesn't make a difference whether or not the specified include file exists or not, which makes me doubt you can just 'include' a file like this at all.

What am I doing wrong here? Is there a more obvious / straight forward way to customize a jenkins-jobs run?

Update:

I somehow managed to use the !include tag for individual items now, like this:

- dynamic-config: &dynamic-config
    name: "dynamic-config"
    folder-prefix: !include: job-configs/active/folder-prefix.inc
    branch-name: !include: job-configs/active/branch-name.inc
    node-name: !include: job-configs/active/node-name.inc

But I wasn't able to put the whole dynamic-config element (with the anchor) into an include file yet.

2nd update:

Looks like I'm trying something similar as the guy from this question. Can someone confirm, that this is currently still a problem? What's the JJB way of handling this?

frans
  • 8,868
  • 11
  • 58
  • 132

0 Answers0