With JJB (Jenkins Job Builder) is it possible to set environment variables without making them a job parameter?

222 views Asked by At

I'd like to set a bunch of variables to be used inside JJB-created pipeline-scm job scripts, e.g. details about CI infrastructure.

It's possible to set those variables using parameters:

- job:
    name: "some-job"
    project-type: pipeline
    pipeline-scm:
      ...
    parameters:
      - string:
          name: NODE
          default: "{node}"

NODE can now be used inside a Groovy-Script like this:

node(env.NODE) {
   stage('Checkout') {
   ...
   }
   stage(..){..}
}

But now NODE is a job parameter which on the one hand can be changed (which I don't want) and it's being shown next to job parameters I want to be visible and changeable.

Is there a way to just define environment variables for a Jenkins job (like folder properties, i.e. not visible on the "Build with properties" page)?

1

There are 1 answers

0
Kiwi On

Use the envinject plugin and define the environment variables as properties-content

- job:
    properties:
      - inject:
          properties-content: "NODE={node}"