xcode 从命令行运行时 xcodebuild 命令给出的结果与从 Jenkins 内运行时的结果不同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13500793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:09:26  来源:igfitidea点击:

xcodebuild commands give different results when run from the command line than when run from within Jenkins

xcodejenkinsxcodebuild

提问by Gruntcakes

I'm setting up a CI system using Jenkins and was finding that the build was failing because xcodebuild reports there are no schemes when I was executing the line

我正在使用 Jenkins 设置 CI 系统并发现构建失败,因为 xcodebuild 报告在我执行该行时没有方案

-xcodebuild -workspace XXX -scheme NNN.

-xcodebuild -workspace XXX -scheme NNN。

I couldn't figure out why this could be happening, so to eliminate something screwy being up with my workspace I created a new project template using XCode and found that I am getting a difference in behavior for any xcodebuild command and for any workspace/project.

我无法弄清楚为什么会发生这种情况,所以为了消除我的工作区出现的问题,我使用 XCode 创建了一个新的项目模板,发现对于任何 xcodebuild 命令和任何工作区/项目,我的行为都有所不同.

The template project was called scrap and if from the terminal command line I run this command for example:

模板项目被称为废品,如果我从终端命令行运行这个命令,例如:

  xcodebuild -list

It outputs

它输出

Information about project "scrap":
    Targets:
        scrap

    Build Configurations:
        Debug
        Release

    If no build configuration is specified and -scheme is not passed then "Release" is used.

    Schemes:
        scrap

But if I run xcodebuild -list from within Jenkins then the output instead is:

但是如果我在 Jenkins 中运行 xcodebuild -list 那么输出是:

Building in workspace /Users/Shared/Jenkins/Home/workspace/scrap
[scrap] $ /bin/sh -xe /var/folders/ph/s6dvlfq9769741g_yzmjlmz000007c/T/hudson3765407964219991487.sh
+ xcodebuild -list
Information about project "scrap":
    Targets:
        scrap

    Build Configurations:
        Debug
        Release

    If no build configuration is specified and -scheme is not passed then "Release" is used.

    This project contains no schemes.

This is the most simple of jenkins jobs - all I do is create a new job, set it to a free-style software project, then add a build step of Execut shell and add the xcodebuild -list command, that's it.

这是 jenkins 工作中最简单的——我所做的就是创建一个新工作,将其设置为自由风格的软件项目,然后添加 Execut shell 的构建步骤并添加 xcodebuild -list 命令,就是这样。

Why is xcodebuild saying there are no schemes when there are? And why is it behaving differently when run from within Jenkins?

为什么 xcodebuild 说没有方案时有方案?为什么从 Jenkins 内部运行时它的行为会有所不同?

回答by poxion

Figured out that all you need to do is to set the scheme to be shared. Scheme > Manage Schemes Make sure "Shared" is checked.

弄清楚您需要做的就是设置要共享的方案。方案 > 管理方案 确保选中“共享”。

This will then generate out a new folder/file .../xcshareddata/xcschemes/???.xcscheme

这将生成一个新的文件夹/文件 .../xcshareddata/xcschemes/???.xcscheme

Check this file into your source control and scheme should now appear on your jenkins box.

将此文件检查到您的源代码管理中,并且方案现在应该出现在您的 jenkins 框中。

回答by SuperHappy

you must ignore your .xcodeproj/xcuserdata/.xcuserdatad in your .gitignore file. xcodebuild -list get schemes from .xcodeproj/xcuserdata/.xcuserdatad/xcschemes. jenkins server has no this file so get no schemes,you can open *.xcodeproj in your jenkins server,it will create the file and then do xcodebuild -list can get the current schemes.I have the same problem and solved by the method above.

您必须忽略.gitignore 文件中的.xcodeproj/xcuserdata/.xcuserdatad。xcodebuild -list 从.xcodeproj/xcuserdata/.xcuserdatad/xcschemes获取方案。jenkins服务器没有这个文件所以没有scheme,你可以在你的jenkins服务器中打开*.xcodeproj,它会创建文件然后做xcodebuild -list可以获得当前scheme。我有同样的问题,通过上面的方法解决.