I run job like this:
def job = build job: job_name, parameters:
[
string(name: 'Param1', value: Value1),
string(name: 'Param2', value: Value2),
string(name: 'Param3', value: Value3),
], wait: false
return job
I use wait: false
because I need to run few in same time and then waiting for all of them finished. But in this case job is null because I use wait: false
.
Maybe do you know other way to run multiply jobs in same time and get their objects ?
Other way that I try:
def buildsNumberStart = GetLastDockerBuildNumber(DockerBuildJobName)
def finishedJobs = overrideBranches.collect { item -> RunJobBuild(item.Tag, author, GetImageNameFromRepository(item.DockerRepository), item.Name, item.Branch, item.Repository, DockerBuildJobName)}
sleep(30)
def buildNumberFinish = GetLastDockerBuildNumber(DockerBuildJobName)
while(true)
{
if (IsAllDockerBuildJobsFinished(buildsNumberStart, buildNumberFinish, DockerBuildJobName))
{
break;
}
sleep(5)
}
for (build in GetFinishedJobs(buildsNumberStart, buildNumberFinish, DockerBuildJobName))
{
def listener = build.getListener()
build
.getEnvironment(listener)
.each
{
// HERE IS PROBLEM, I saw just environment variables that
// set on start and didn`t see that I added in pipeline
println it
}
}
}
@NonCPS
def GetFinishedJobs(buildNumbersStart, buildNumberFinish, String dockerBuildJobName)
{
return jenkins.model.Jenkins
.instance
.getItemByFullName(dockerBuildJobName)
.builds
.findAll { it.number > buildNumbersStart && it.number <= buildNumberFinish}
}
CodePudding user response:
I find solution https://stackoverflow.com/a/40148397/14392639 for my case its looks like:
def jobs = [:]
some_source.each
{
item -> jobs[some_source.Name] = build job: job_name, parameters:
[
string(name: 'Param1', value: Value1),
string(name: 'Param2', value: Value2),
string(name: 'Param3', value: Value3),
]
}
parallel jobs