如何从 Jenkins 发送变量以便 Postman 环境可以接收它们?
How to send variables from Jenkins so that the Postman environment can take them?
目前我有一个名为 URL 的环境变量,我在其中添加了我需要用于每个端点的 url,但是,我想知道是否可行从 Jenkins 更改此环境变量以指示另一个 url,例如想要在 QA、DEV、Production 等环境中工作。如果可能,我如何将该信息发送到我的集合(json) 的环境变量?
这是我当前的 JenkinsFile
pipeline {
agent any
stages {
stage('Running tests') {
steps {
echo 'Testing'
sh "newman run postman_collection.json -e .postman_environment.json"
}
}
}
}
您可以使用 --global-var
或 --env-var
将数据从 Jenkins 传递到集合中。
如果集合中使用了 {{foo}}
全局变量,它会将其解析为 bar
值。
--global-var "foo=bar"
对于您的 Jenkins 示例,您需要这样的东西:
pipeline {
agent any
stages {
stage('Running tests') {
steps {
echo 'Testing'
sh "newman run postman_collection.json -e .postman_environment.json --env-var 'variableName=$JENKINS_VARIABLE'"
}
}
}
}
目前我有一个名为 URL 的环境变量,我在其中添加了我需要用于每个端点的 url,但是,我想知道是否可行从 Jenkins 更改此环境变量以指示另一个 url,例如想要在 QA、DEV、Production 等环境中工作。如果可能,我如何将该信息发送到我的集合(json) 的环境变量?
这是我当前的 JenkinsFile
pipeline {
agent any
stages {
stage('Running tests') {
steps {
echo 'Testing'
sh "newman run postman_collection.json -e .postman_environment.json"
}
}
}
}
您可以使用 --global-var
或 --env-var
将数据从 Jenkins 传递到集合中。
如果集合中使用了 {{foo}}
全局变量,它会将其解析为 bar
值。
--global-var "foo=bar"
对于您的 Jenkins 示例,您需要这样的东西:
pipeline {
agent any
stages {
stage('Running tests') {
steps {
echo 'Testing'
sh "newman run postman_collection.json -e .postman_environment.json --env-var 'variableName=$JENKINS_VARIABLE'"
}
}
}
}