Jenkins windows batch command variables




















Note: The bat "set" command shows environment variables in Windows. Click the Build Now link on the left-hand side to create a new pipeline build. The Console Output page displays the output of the shell command. In this case, it is a list of Jenkins environment variables:. This code demonstrates both methods of reading the variable:.

Note: It is generally better to use the env object when reading environment variables since this reduces the chance of confusing the short variable name with another object. Users can set Jenkins environment variables on a global or local level.

Add global environment variables through the Jenkins dashboard, while local variables are added using declarative, imperative, and scripted pipelines.

In Jenkins, any pipeline or job can access and read global environment variables. To add a new global environment variable using the Jenkins dashboard:. Scroll down until you reach the Global properties section. Check the box next to Environment variables and click the Add button to add a new variable. You can set a local environment variable in Jenkins using the declarative pipeline. Placing this block at the beginning of the pipeline means the variable is available for use at any step of the pipeline.

Placing it at a particular stage means it is only available during the steps of that stage and that stage only. Another method is to use an env object in a script to imperatively define an environment variable:. As an example, this code uses all three methods outlined above in a single pipeline to set local environment variables:. The console output for this pipeline shows that Jenkins is able to successfully access and read every variable:. Adding the EnvInject plugin to Jenkins allows you to inject environment variables during the build startup.

This is particularly useful when creating a freestyle project in Jenkins. There is also a variable syntax using! This is a special type of situation called delayed expansion. You can read the command line arguments passed to your script using a special syntax. The zero ordinal argument is the name of the batch file itself.

NOTE: DOS does support more than 9 command line arguments, however, you cannot directly read the 10th argument of higher. You will learn how to process a large number of arguments in a loop later in this series. Command Line Arguments also support some really useful optional syntax to run quasi-macros on command line arguments that are file paths.

These macros are called variable substitution support and can resolve the path, timestamp, or size of file that is a command line argument. I use this trick in nearly every batch file I write to determine where the script file itself lives.

I also use this trick frequently to determine the name of the script at runtime. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Hot Network Questions. Question feed.



0コメント

  • 1000 / 1000