Hi, I found a way of creating it via the script console (in reference to an
answer in this group). Maybe this could help others in the future
instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
EnvironmentVariablesNodeProperty.class)
newEnvVarsNodeProperty = null
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("Username", "myUsername")
envVars.put("Password", "myPassword")
instance.save()
you can add as many as you want and this would create the env vars. I also
found the piece of code on StackOverflow which creates a pipeline but I
would like to create multiple pipelines and not just one. any idea how to
do this with the code below?
import hudson.plugins.git.*;
def scm = new GitSCM("[email protected]/yourRepo.git")
scm.branches = [new BranchSpec("*/TestBranch")];
def flowDefinition = new
org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition(scm, "Jenkinsfile")
def parent = Jenkins.instancedef job = new
org.jenkinsci.plugins.workflow.job.WorkflowJob(parent, "New Job")
job.definition = flowDefinition
parent.reload()
On Saturday, 16 March 2019 17:35:56 UTC+1, Ivan Fernandez Calvo wrote:
>
> For pipelines take a look to the environment directive documentation
> https://jenkins.io/doc/pipeline/tour/environment also you can define
> variable by asigning a value to env variable
>
> script { env.VARIABLE_NAME = ’value’ }
>
> See also
> https://jenkins.io/doc/book/pipeline/shared-libraries/
>
> https://wiki.jenkins.io/plugins/servlet/mobile?contentId=58000129#content/view/58000129
>
>
>
> To set environment variables or properties at Jenkins start time you could
> use init scripts
> https://wiki.jenkins.io/plugins/servlet/mobile?contentId=38142057#content/view/3814205
>
> or CasC https://jenkins.io/projects/jcasc/
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/1e321b1e-d1e3-4662-be78-c2057faff475%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.