【问题标题】:jq: error: syntax error, unexpected '-', expecting '}' (Unix shell quoting issues?) at <top-level>, line 1:jq: 错误:语法错误,意外的 \'-\',期待 \'}\'(Unix shell 引用问题?)在 <top-level>,第 1 行:
【发布时间】:2022-12-12 00:46:59
【问题描述】:

我正在尝试在 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:

`

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

`

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

【问题讨论】:

    标签: jenkins jenkins-pipeline sh jq ssh-agent


    【解决方案1】:

    您必须在双引号内转义双引号:

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

    【讨论】:

    • 没运气!同样的结果!
    • @KapilYadav 你能以某种方式启用运行哪个确切命令的调试输出吗?你能试试双反斜杠,即{\"kubeconfig-file\"}吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    相关资源
    最近更新 更多