Renato Ivancic - Software Engineer

Background image

Jenkins hints

Backend

Jenkins

The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

Isolated environment variables

I needed to set environment specific variables for the job. They can not be saved in the pipeline script itself which is in git repository, because it is executed from multiple different Jenkins servers. Every one of the them needs to set different variables. Also the global environmental variables of the Jenkins itself are not an option, because variables that I need are specific for just one job inside server. I found the solution with the EnvInject Plugin. This plugin makes it possible to have an isolated environments for your jobs.

I’ve set them under the job configurations. Below is the screenshot with some variables set:

Jenkins

The pipeline script now sets specific job variables. I don’t want that the variables from configuration are reused all over the script so I extracted them to the global pipeline environment block. More about using environment variables.

pipeline {
    agent none

  environment {
    ...
    REPO_NAME="${JENKINS_REPO_NAME}"
    REPO_TEST_ID="${JENKINS_REPO_TEST_ID}"
    SERVICE_TEST_ID="${JENKINS_SERVICE_TEST_ID}"
    CREDENTIALS_TEST_ID="${JENKINS_CREDENTIALS_TEST_ID}"
    ...
}

Sources

EnvInject Plugin
jenkins.io

#jenkins