ios - 如何在 Jenkins Groovy 的 ssh 命令中转义美元符号?

标签 ios shell jenkins groovy ssh

我有一个用于 iOS 工作的 groovy 文件。 version=$( 在尝试构建时出现语法错误。如果我用 \$ 转义该符号,则该行不起作用。我该如何解决它?

stage('XCode')
{
     sh """
     if [ "${appName}" == "" ]; then
         echo "INVALID appName!"
         exit 1
     fi
     if [ "${schemeName}" == "" ]; then
         echo "INVALID Scheme Name!"
         exit 1
     fi

     /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNumber}" "${WORKSPACE}/iOS_App/App/Supporting Files/AppProd-Info.plist"
     /usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${WORKSPACE}/iOS_App/App/Supporting Files/AppProd-Info.plist"

     version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${WORKSPACE}/iOS_App/App/Supporting Files/AppProd-Info.plist")
     /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNumber}" "${WORKSPACE}/iOS_App/App/AppNotifServiceExtensionProdInfo.plist" 
     /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" "${WORKSPACE}/iOS_App/App/AppNotifServiceExtensionProdInfo.plist" 

     /usr/bin/xcodebuild -quiet -workspace iOS_App/${workspaceName} -scheme ${schemeName} -sdk iphoneos -configuration Release archive -archivePath ${WORKSPACE}/build/${appName}.xcarchive
     /usr/bin/xcodebuild -exportArchive -archivePath ${WORKSPACE}/build/${appName}.xcarchive -exportOptionsPlist 'iOS_App/App/Supporting Files/${environment}_ExportOptions.plist' -exportPath ${WORKSPACE}/build
     """
}

我已经转义了美元符号,但出现以下错误:

groovy.lang.MissingPropertyException: No such property: version for class: groovy.lang.Binding

最佳答案

我通过在使用它的地方转义美元符号来解决这个问题。将 \ 添加到 :CFBundleShortVersionString\$version 解决问题。

关于ios - 如何在 Jenkins Groovy 的 ssh 命令中转义美元符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57990149/

相关文章:

ios - 将子实体追加到核心数据 iOS Swift 中的实体

linux - 如何删除一个文件的第一个值未出现在另一个文件中的行?

jenkins - 在管道 Jenkinsfile 中导入 groovy 类

python - 如何在不指定文件扩展名的情况下运行 python 脚本(跨平台解决方案)?

带标签或节点的Jenkins管道代理调用从节点?

jenkins - 在 Jenkins 管道中设置节点标签

iphone - 使用NSSortDescriptor对特定项目进行排序的数组

ios - 如何居中 TabBarItem - Swift

objective-c - 为什么是 "(UIButton *)sender"而不是 "UIButton *sender"?

shell - 在 shell 脚本之间传递参数但保留引号