Jenkins
Jenkinsfile
See Jenkinsfile
code in my repo
hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT
[Service]
Environment="JAVA_OPTS=-Dhudson.model.DirectoryBrowserSupport.CSP= -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
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.
- In Jenkins, any pipeline or job can access and read global environment variables. Go to
Dashboard
→Configure System
→Global properties
→Environment variables
. -
Jenkins local Environment Variables:
-
You can set a local
environment
variable in Jenkins using the declarative pipeline.Note
- An
environment
directive used in the top-levelpipeline
block will apply to all steps within the Pipeline. - An
environment
directive defined within astage
will only apply the given environment variables to steps within thestage
.
- An
-
Or using an
3.Or using aenv
object in a script to imperatively define an environment variable:withEnv([]) {}
block sets a local environment variable as part of a scripted pipeline: - You can use the Environment Injector plugin.
-
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:
- The
withEnv([]) { }
block overrides any environment variable. - Variables set using the
env
object cannot override those set using theenvironment {}
block. - Variables set using the
env
object can only override other variables set with theenv
object.