我想通过 Ansible 中执行的 Groovy 脚本(YAML 文件(设置 Jenkins 全局属性 - 环境变量。
我试过以下
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
instance = Jenkins.getInstance()
envVars.put("FOO1", "bar1")
envVars.put("FOO2", "bar2")
instance.save()
为什么这不起作用?
以这种方式完成:
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
envVars = null
if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
globalNodeProperties.add(newEnvVarsNodeProperty)
envVars = newEnvVarsNodeProperty.getEnvVars()
} else {
envVars = envVarsNodePropertyList.get(0).getEnvVars()
}
envVars.put("name", "value")
instance.save()