jenkins with env
时间: 2023-10-20 08:26:15 浏览: 47
Jenkins is an open-source automation server that is used to build, test, and deploy software projects. It has a powerful feature called `env` which allows you to define environment variables that can be used in your Jenkins pipeline or freestyle job.
You can define an environment variable in Jenkins by going to your pipeline or freestyle job's configuration page and selecting the "This project is parameterized" option. Then, add an "Environment Variable" and specify the name and value of the variable.
For example, if you want to define an environment variable called `MY_VAR` with a value of `hello`, you would add an "Environment Variable" with the name `MY_VAR` and the value `hello`.
Once you have defined an environment variable, you can use it in your pipeline or freestyle job by referencing it with the `${env.MY_VAR}` syntax.
For example, if you want to print the value of `MY_VAR` in your pipeline, you can use the following code:
```
pipeline {
agent any
stages {
stage('Example') {
steps {
echo "My variable is ${env.MY_VAR}"
}
}
}
}
```
This will print "My variable is hello" in the Jenkins console output.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)