John Seen
John Seen

Reputation: 731

jq: select is not recognized as an internal or external command

I am trying to using jq within Jenkins pipeline code, but it gives,

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,

Sample 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": {

                }
              }
            ]
          }
        }
      }
    }
  ]
}

Do we need to escape the JSON?

Upvotes: 0

Views: 2638

Answers (1)

gears
gears

Reputation: 743

The jq command runs fine against the sample input - see here (if someone is trying it on their own, do not paste the single quotes ' in the Filter input line).

The whole external command is executed with bat, so it is on Windows...could you remove the \ characters and try? On Linux, \ continues the command on a new line (was it ^ on Windows?)...

Upvotes: 2

Related Questions