Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jq: error: syntax error, unexpected '-', expecting '}' (Unix shell quoting issues?) at <top-level>, line 1:

I am trying to run some jq command over ssh-agent in a Jenkins pipeline. But I am getting the following error:
Trying to run:
`

        stage("common-infra-deployment"){
            steps{
                sshagent (credentials: ['test-private-key']){
                    script{
                       
                        sh '''
                        sudo ssh -o StrictHostKeyChecking=no hci@10.x.x.x "
                        jq '.outputs | {"kubeconfig-file"}' terraform.tfstate;
                        "
                        '''

                    }
                }
            } 
        }

`

Error:
`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

jq: error: syntax error, unexpected '-', expecting '}' (Unix shell quoting issues?) at <top-level>, line 1:

`

terraform.tfstate
`

{
"outputs": {
    "kubeconfig-file": {
      "value": "/home/chi/jenkins-terraform/config",
      "type": "string"
    },
    "master-node-ip": {
      "value": "x.x.x.x",
      "type": "string"
    },
    "master-node-vm-name": {
      "value": "v1",
      "type": "string"
    },
    "worker-node-ip": {
      "value": "x.x.x.x, x.x.x.x, x.x.x.x",
      "type": "string"
    },
    "worker-node-vm-names": {
      "value": "v2, v3, v4",
      "type": "string"
    }
  }
}

`

I tried \ to escape ‘-‘ and ‘{}’ but nothings working out.
I want the jq to be executed over ssh session.

>Solution :

You must escape your double quotes inside your double quotes:

sudo ssh -o StrictHostKeyChecking=no hci@10.x.x.x "
jq '.outputs | {\"kubeconfig-file\"}' terraform.tfstate;
"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading