我正在尝试在Jenkins管道代码中使用jq
,但是它给出了
stage('sad') {
steps {
bat """oc new-app abc/openshift-mysql:22 --output=json --dry-run=true | \ jq '.items[] | select(.kind == "DeploymentConfig") | .spec.template.spec.containers[0].env +=
[{"name":"db_name","valueFrom":{"secretKeyRef":{"key":"database-name","name":"mysql"}}},{"name":"db_username","valueFrom":{"secretKeyRef":{"key":"database-user","name":"mysql"}}},{"name":"db_password","valueFrom":{"secretKeyRef":{"key":"database-password","name":"mysql"}}}]'
| \ oc apply --filename -"""
}
}
'select' is not recognized as an internal or external command,
示例JSON,
{
"kind": "List",
"apiVersion": "v1",
"metadata": {
},
"items": [
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "openshift-mysql",
"creationTimestamp": null,
"labels": {
"app": "openshift-mysql"
},
"annotations": {
"openshift.io/generated-by": "OpenShiftNewApp"
}
},
"spec": {
"strategy": {
"resources": {
}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"openshift-mysql"
],
"from": {
"kind": "ImageStreamTag",
"namespace": "abc",
"name": "openshift-mysql:22"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"app": "openshift-mysql",
"deploymentconfig": "openshift-mysql"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "openshift-mysql",
"deploymentconfig": "openshift-mysql"
},
"annotations": {
"openshift.io/generated-by": "OpenShiftNewApp"
}
},
"spec": {
"containers": [
{
"name": "openshift-mysql",
"image": "172.30.1.1:5000/abc/openshift-mysql:22",
"ports": [
{
"containerPort": 8080,
"protocol": "TCP"
}
],
"resources": {
}
}
]
}
}
}
}
]
}
我们需要转义JSON吗?
答案 0 :(得分:1)
jq
命令在示例输入上运行良好-请参见here(如果有人自己尝试,请勿在过滤器输入行中粘贴单引号'
)
整个外部命令都是使用bat
执行的,因此它在Windows上...您可以删除\
字符并尝试吗?在Linux上,\
在新行上继续执行命令(在Windows上是^
吗?)...