【问题标题】:How to pass "Json string" from groovy variable to shell variable with in the groovy function如何在 groovy 函数中将“Json 字符串”从 groovy 变量传递到 shell 变量
【发布时间】:2021-05-10 22:07:46
【问题描述】:

我正在尝试为 jenkins 创建共享库来构建应用程序。当我尝试将 json 字符串从 groovy 函数传递到 shell 块以执行构建命令时。而 json 字符串不带引号传递。如何保留引号。

stage('build app') {
      steps {
          script { 
                build project:"TestApp.xcodeproj",
                workspace: "TestApp.xcworkspace",
                scheme: "Develop",
                config: "Debug", 
                target: "{ "TestApp": { "info_plist": "TestApp/Info.plist", "profile_name": "Test App Debug (January 2021)", "app_id": "com.******.Debug" } }"                    
                }
            }
        }
def build(Map buildParams) {
     sh """#!/bin/bash -l
          export XCODE_PROJ="${buildParams.project}"
          export XCODE_WORKSPACE="${buildParams.workspace}"
          export XCODE_BUILD_SCHEME="${buildParams.scheme}"
          export XCODE_BUILD_CONFIGURATION="${buildParams.config}"
          export XCODE_TARGET_JSON="${buildParams.target}"

          #build App
         fastlane build app    
      """
}

期待 json 字符串,因为它在带有“引号”的 shell 块中。而得到错误期望'}'发现:.当我转义 json 字符串的引号时,获取没有“引号”的值

{ TestApp: { info_plist: TestApp/Info.plist, profile_name: Test App Debug (January 2021), app_id: com.******.Debug } }

这导致 fastlane 抛出错误无效令牌。如何在 shell 块变量中保留引号

【问题讨论】:

    标签: shell jenkins groovy


    【解决方案1】:

    用反斜杠()转义json字符串中的引号对我有用。

    '{ "TestApp": { "info_plist": "TestApp/Info.plist", "profile_name": "Test App Debug (January 2021)", "app_id": "com.******.调试" } }'

    【讨论】:

      猜你喜欢
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 2011-02-12
      • 2017-01-09
      • 2020-02-06
      相关资源
      最近更新 更多