Перейти к содержанию

Jenkins

Jenkinsfile

See Jenkinsfile code in my repo

hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT

sudo systemctl edit jenkins
[Service]
Environment="JAVA_OPTS=-Dhudson.model.DirectoryBrowserSupport.CSP= -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
sudo systemctl restart jenkins

JENKINS-68571

How to see Environment Variables in Jenkins

Open: http://127.0.0.1:8080/env-vars.html/

If necessary, replace 127.0.0.1:8080 with the address of your Jenkins server.

How to set Environment Variable in a Jenkins Pipeline

Note

Declarative Pipeline supports an environment directive, whereas users of Scripted Pipeline must use the withEnv step.

  1. In Jenkins, any pipeline or job can access and read global environment variables. Go to DashboardConfigure SystemGlobal propertiesEnvironment variables.
  2. Jenkins local Environment Variables:

    1. You can set a local environment variable in Jenkins using the declarative pipeline.

         environment {
             DEPLOY_TO = 'staging'
         }
      

      Note

      • An environment directive used in the top-level pipeline block will apply to all steps within the Pipeline.
      • An environment directive defined within a stage will only apply the given environment variables to steps within the stage.
    2. Or using an env object in a script to imperatively define an environment variable:

      script {
          env.DEPLOY_TO = "staging"
      }
      
      3.Or using a withEnv([]) {} block sets a local environment variable as part of a scripted pipeline:
      withEnv(["DEPLOY_TO=staging"])
      

    3. You can use the Environment Injector plugin.

Documentation

How to override Environment Variable in Jenkins

The Jenkins pipeline allows users to override environment variables, changing the current value of the variable with a new one.

The override process follows several rules when determining variable priority:

  1. The withEnv([]) { } block overrides any environment variable.
  2. Variables set using the env object cannot override those set using the environment {} block.
  3. Variables set using the env object can only override other variables set with the env object.

String interpolation

def username = 'Jenkins'
echo 'Hello Mr. ${username}'
echo "I said, Hello Mr. ${username}"
Hello Mr. ${username}
I said, Hello Mr. Jenkins

Documentation