build job: 'build_Test', parameters: [validatingString(name: 'version', value: '1.0.0.1'), string(name: 'TASK', value: 'build')]
I am trying to trigger another job via jenkinfile. The above script triggers the job but can see below error in the triggered job's console log
java.lang.NullPointerException
at java.util.regex.Pattern.<init>(Pattern.java:1350)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at java.util.regex.Pattern.matches(Pattern.java:1133)
at hudson.plugins.validating_string_parameter.ValidatingStringParameterValue.createBuildWrapper(ValidatingStringParameterValue.java:87)
ValidateString Parameters should have the following options. And it seems your regex is null.
validatingString(name: "test", defaultValue: "", regex: /^abc-[0-9]+$/, failedValidationMessage: "Validation failed!", description: "ABC")
Related
I can run a new job with from a different job with build job: 'jobname'
But my new job also requires a stashed file parameter. Can this be included in the
parameters[] ?
Yes it can, you can use the method stashedFile
parameters([
string(name: "Name", defaultValue: "val", description: "description"),
stashedFile(name: "name", description: "description")
])
and later access it using the unstash method and pass it the value that was passed to the name argument of stashedFile
I am looking for solution to pass a 'file' (.csv) parameter value to downstream job. I have tried with below code but its not working.
build job: "DownstreamJobName",
parameters: [
string(name: 'Releases', value: "1.2.9"),
[$class: "FileParameterValue", name: "test.csv", file: new FileParameterValue.FileItemImpl(new File(env.WORKSPACE/env.filepath))],
string(name: 'UserEmail', value: "testemail")
]
When I got researched got below link that there is an existing defect with file for Jenkins pipeline, dont know whether it got fixed or not. https://issues.jenkins.io/browse/JENKINS-27413
I am able to solve this like below
propertiesFilePath = "${env.WORKSPACE}/test.csv"
parameters: [
[$class: "FileParameterValue", name: "test.csv", file: new FileParameterValue.FileItemImpl(new File(propertiesFilePath))]
]
I have a pipeline project say "A" which is string parameterized, and I am trying to call another build say "B" which is also string parameterized, using the command as follows :
build job: 'B', parameters: [[$class: 'StringParameterValue', name: 'tagg', value: "$env.tag"]]
The target is used to pass the parameter which was taken as input from A and assign use it in B.I tried to receive the parameter echo "$env.tagg" which gave null, echo "$tagg" gave no such parameter found error.
So how do I receive the parameters sent from A in B.
I think you need to let Jenkins know what env.tag is, try something like:
build job: 'B', parameters: [[$class: 'StringParameterValue', name: 'tagg', value: String.ValueOf($env.tag)]]
Lets assume a scenario where Job A calls Job B:
...
...
...
crID = build (job: "Open Change Request", wait: true, parameters: [
string(name: "assignedTo", value: "${BUILD_USER_EMAIL}"),
string(name: "crType", value: "Upgrade worker nodes"),
string(name: "environment", value: "${region}")]).result
The above code is flawed, as result will return FAILURE, SUCCESS, etc...
What I require is to actually retrieve the value that Job B generates.
Is this at all possible, to retrieve the response of the job that ran as part of a build step?
Possibilities:
Read log from the other job?
Global properties?
I ended up doing so by reading the build log.
In job B print the value to log:
echo "Change Request ID:${crID}"
In job A process the log text to get the printed value:
openCrRawData = build (job: "Open Change Request", wait: true, parameters: [
string(name: "assignedTo", value: "${jobInitiator}"),
string(name: "crType", value: "Upgrade worker nodes"),
string(name: "environmentsForCR", value: "${region}")])
crIDRaw = sh (script: "echo \"${openCrRawData.rawBuild.log}\" | grep \"Change Request ID:\"", returnStdout: true).trim().split(":")
crID = crIDRaw[1]
How can I pass choice parameters for the downstream job when called inside a stage in the jenkins pipeline?
I tried the below solutions but none worked:
stage('build job') {
steps{
script{
build job: 'test',
parameters: [
choice(choices: "option1\noption2\noption3\n", description: '', name: 'choiceParam')
]
}
}
}
fails with java.lang.UnsupportedOperationException: no known implementation of class hudson.model.ParameterValue is using symbol ‘choice’
Tried these as well:
parameters:
[
[$class: 'ChoiceParameterValue', name: 'choiceParam', value: "1\n\2\n3\n"],
]
fails with java.lang.UnsupportedOperationException: no known implementation of class hudson.model.ParameterValue is named ChoiceParameterValue
I actually want to pass the choice parameter as a build parameter like "$choiceParam" for value so that I can just update the jenkins job configuration instead of always updating the values in the pipeline script
Can someone please help me with this
Thanks
When you are building a job via the Build step, you are kicking it off so you need to have "selected" a value.
In this instance you would pass in the desired 'String' choice. Not a list of choices. i.e. "1"
We create our list of params and then pass that in. So: our current job has these input params:
choice(name: 'ENV', choices: product, description: 'Env'),
choice(name: 'ENV_NO', choices: envParams(product), description: 'Env No'),
We pass these downstream by setting them:
List<ParameterValue> newParams = [
new StringParameterValue('ENV', params.ENV),
new StringParameterValue('ENV_NO', params.ENV_NO),
]
build(job: "job", parameters: newParams, propagate: false)