拥有一个 Jenkins 作业,它会触发应用程序构建,从 iPhone 卸载以前的应用程序构建并安装新构建的应用程序,然后运行自动化测试套件。 在 Jenkinsfile 中,卸载/安装过程如下所示:
stage ('Install XXX') {
options {
timeout(20)
}
steps {
s3CopyArtifact buildSelector: lastSuccessful(), excludeFilter: '', filter: '', flatten: true, optional: false, projectName: 'build-XXX-ios', target: 'utility'
sh """
cd utility;
unzip -o "*.zip"
xcrun devicectl device uninstall app --device ${env.PHONE} ${APP}
xcrun devicectl device install app --device ${env.PHONE} \"XXX.app\"
xcrun devicectl device process launch --device ${env.PHONE} --start-stopped ${APP}
"""
}
}
卸载时出现错误:
+ xcrun devicectl device uninstall app --device XXXXXXX-XXXXXXXXXXX com.XXX.XXXXXX
xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find devicectl 2> /dev/null' failed with exit code 17664: (null) (errno=Invalid argument)
xcrun: error: unable to find utility "devicectl", not a developer tool or in PATH
Jenkins 代理的路径如下所示:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/build_tools
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:/usr/local/lib:/bin:/usr/local/bin:$PATH
尝试安装Xcode命令行工具,重新连接iPhone,将iPhone连接到另一个USB插座。 xcrun devicectl list devices 命令正常工作,并且 iPhone 在那里可见。
当我将 jenkins 文件夹中的 run-slave.sh 文件中的 PATH 更改为以下内容时,问题得到解决:
export ANDROID_HOME=~/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/build_tools:/Applications/Xcode.app/Contents/Developer/usr/bin:$JAVA_HOME/bin:/usr/local/lib:/bin:/usr/local/bin:/usr/bin:$PATH