jenkins jq:error:语法错误,在第1行出现意外的“-”,应为“}”(Unix shell引用问题?)< top-level>:

ckx4rj1h  于 2022-12-17  发布在  Jenkins
关注(0)|答案(1)|浏览(188)

我尝试在Jenkins管道中的ssh-agent上运行一些jq命令,但是我得到了以下错误:尝试运行:'

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;
                        "
                        '''

                    }
                }
            } 
        }

'
错误:'

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

'
地形

{
"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"
    }
  }
}

'
我试过\转义'-'和'{}',但没有成功。我希望jq在ssh会话上执行。

6uxekuva

6uxekuva1#

双引号内的双引号必须转义:

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

也许反斜杠本身需要转义:

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

相关问题