Reputation: 595
I have microservices.json
file which looks like this:
[
{
"build": "cat",
"microservices": [
"a",
"b"
]
},
{
"build": "dog",
"microservices": [
"a",
"b"
]
}
]
I have a jenkinsfile
, which has a matrix
structure like below:
pipeline {
agent { label 'Ubuntu' }
environment{
def microserviceBuild = readJSON file: 'microservices.json'
def builds = "${microserviceBuild[0].build}" // how to get each build property value ?????
//def builds = new JsonSlurper().parseText( microserviceBuild )
}
stages {
stage('Build') {
matrix {
axes {
axis {
name 'BUILD'
values 'cat', 'dog' // <--------------- how to pass builds list here????
}
}
stages {
stage('Check values'){
steps {
pwsh """
Write-Host ${BUILD}
"""
}
}
}
}
}
}
}
Running def microserviceBuild = readJSON file: 'microservices.json'
alone in Jenkins throws a error message below:
hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84) at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:77) at org.jenkinsci.plugins.pipeline.utility.steps.AbstractFileOrTextStepExecution.run(AbstractFileOrTextStepExecution.java:32) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Finished: FAILURE
build
values as list using readJSON
?build
values to the matrix axis values? Is it possible?Thanks
Upvotes: 0
Views: 1012
Reputation: 3076
Dynamic axis values are not supported in Declarative Pipeline as of now .
There is a jenkins issue created for it. It accepts only string literals.
https://issues.jenkins.io/browse/JENKINS-62127
Upvotes: 0
Reputation: 1242
As I know it is not possible to use variables in matrix.
Upvotes: 0