Can you set different XCode Builder settings per project in Jenkins? - jenkins

I'm brand new to Jenkins CI but liking it so far. I have run into one serious issue though. The XCode Builder settings are global settings. I have different projects that require different versions of xcodebuild. Is there a way to define those on a per project basis?
Thanks

There seems to be a way to do this using xcrun and xcode-select.
Run man xcrun and man xcode-select for details.
You may need the xcode command line package installed to see those commands.

Related

Xcode build rules script "command not found" on M1

I have a project that runs some utility I've installed using homebrew on one of its build rules.
On my M1 mac, homebrew is installed on /opt/homebrew/bin.
I have eval "$(/opt/homebrew/bin/brew shellenv)" present in my ~/.zprofile file, but it seems like Xcode doesn't respect that (or maybe overrides it?).
When trying to evaluate the PATH variable during Xcode run script command I get the following:
PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
For clearance, this is the phase I was running, under Build rules.
I've managed to find two workarounds that work with this issue, the first is to symlink the program you want from /opt/homebrew/bin onto /usr/local/bin (protoc in my case)
sudo ln -s /opt/homebrew/bin/protoc /usr/local/bin/protoc
The second is to add the following line to the build rule script:
eval "$(/opt/homebrew/bin/brew shellenv)"
This has the disadvantage of not working on non M1 Macs.
There is a possible, very simple solution provided by this answer.
Basically, freshly upgraded versions of XCode (for example, 13.4.1) running on Apple Silicon-powered Macs (like my M1 MacBook Pro), have components that cannot properly use/output the appropriate object files in all the output platform combinations you need.
This leads to some "interesting" issues and error message cross-overs that find "almost correct" answers on StackOverflow. Hence the many suggestions to exclude "arm64" platform and similar from the build options.
The simple answer to all of that is... to just run XCode with Rosetta enabled. Rosetta will engage with the components that miss the needed cross-platform capabilities.
Here is an example of how to enable an application to use Rosetta. You select the app icon, then go to the File menu and select "Get Info". Then click the "Open using Rosetta" checkbox.

Fastlane Apple Generic versioning not enabled in this project

What I’m doing is trying to make bitbucket pipline do my iOS CD, I included docker fastlanetools/fastlane image and in the steps i pull and run the docker image everything is okay and i was able to let fastlane command work by calling fastlane beta in the steps.
What’s happening is that fastlane exits with the error
Apple Generic versioning is not enabled in this project.
I followed apple documentation to enable it from xCode
from here
I changed all the targets in my project to use App Generic and still not working
In case it was this issue xcrun avgtool xcrun: error: unable to find utility "avgtool", not a developer tool or in PATH
after
sudo xcode-select -s /Applications/Xcode.app
fastlane stopped complaining
In my case it was the issue of Command Line Tools, which wasn't specified under the location tab.
Add your xcodeproj path.
Like
increment_build_number(
xcodeproj: '../XXX.xcodeproj',
build_number: number
)
I met the same problem. I searched and tried a lot of ways, but still not worked it out. A flash of inspiration came to my mind. I set a certain version via increment_version_number, it was succeeded magically. Then I tried increment_version_number again to make it automatically increment the version number. Lucky me, it worked.
I had two installations of macOS but Xcode only on one of them, after updating I lost the command line tools location. After setting that up in the preferences it worked again
What i missed was missed setting CURRENT_PROJECT_VERSION
(whz. Current Project Version) build setting, which specifies the current version of your project.
Reason:
By default, Xcode does not use any versioning system & no value for Current Project Version. So setting versioning system to Apple Generic ensures that Xcode will include all agvtool-generated version information in your project.
Reference
So make sure, your below set values for
I highly recommend using this plugin if your issue is not having argvtool accessible in CI/CD when trying to bump stuff uniformly for both IOS/Android before it does it in the macOS runner or action etc
In my case this problem appeared after I updated Xcode and my xcode-select was pointing to the missing folder.
After I executed xcode-select -s /Applications/Xcode_13_4.app Fastlane continued working as it used to before.

Build phase script is running before needed files are created in Xcode 10

https://github.com/realm/realm-cocoa/blob/master/scripts/strip-frameworks.sh
We are always using this script to remove architectures for dynamic frameworks. It has worked with Xcode 9.
In Xcode 10, it didn't remove the architectures.
Anything in Xcode 10 that could break this?
We have a theory that it is related to the new build system
Solution
The new build system is now running scripts in parallel if its dependency is already available or if it doesn't have any dependency.
The solution is to provide input files to tell "run scripts" not to run yet without those dependencies.
This is more elaborated in this post
Alternative Solution:
We used the legacy build system as a work around.
File > Workspace Settings

specifying DEVELOPER_DIR to choose xcode version have no impact in jenkins

i'm trying to switch between different xcode versions with jenkins and i come to this solution where we inject DEVELOPER_DIR as environment variables
DEVELOPER_DIR=/Applications/Xcode8.1.app/Contents/Developer.
but even if xcodebuild -version show the correct as xcode8.1 my project fail because it uses the other version of xcode7 .
Thanks for your help
There's a lot of info in the documentation for the Xcode plugin, some of which could help you debug your PATH issue, but you'll probably find it easier to just use this plugin to configure Xcode.

List command hangs in xcode

I am using the Jenkins Xcode plugin (https://wiki.jenkins-ci.org/display/JENKINS/Xcode+Plugin) to build an iOS application, however it hangs when running the following command on a project I have inherited from another developer:
$ /usr/bin/xcodebuild -list
It also hangs when I run this command manually from a terminal. Does anyone know what the cause may be? The warning displayed is also displayed on another project I have, but it does not hang in this case.
Running Xcode 6.1 on OS X 10.10
$ /usr/bin/xcodebuild -list
2014-11-12 04:47:21.234 xcodebuild[42642:1431240] [MT] DVTAssertions: Warning in /SourceCache/IDEFrameworks/IDEFrameworks-6604/IDEFoundation/SourceControl/Model/IDESourceControlManager.m:423
Details: Error Domain=com.apple.dt.IDESourceControlErrorDomain Code=-1 "Missing extension: public.vcs.subversion" UserInfo=0x7f9792309200 {NSLocalizedDescription=Missing extension: public.vcs.subversion}
Object: <IDESourceControlManager: 0x7f9792302860>
Method: -loadRepositories
Thread: <NSThread: 0x7f9790d2dbe0>{number = 1, name = main}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
Information about project "DOHSmokefree":
Targets:
DOHSmokefree
DOHSmokefreeTests
Build Configurations:
Debug
Release
If no build configuration is specified and -scheme is not passed then "Release" is used.
TLDR; My solution: Mark the schemes as shared in XCode if building them from the command line as a different user, or without ever opening XCode on the build machine.
I was having this same problem, intermittently on our CI server. I came across this question. The accepted answer with the problem being an issue and fixing the SVN version did not work for me as the SVN being used on the CI server was the default SVN and it was, as mentioned, working intermittently.
What I finally noticed is that, between a working version and a non-working version the schemes were not being listed. I had recently upgraded a library on the project and that got me to thinking about the schemes. After realizing that schemes are stored locally per user, unless shared, the fix for me was to go into the scheme manager and mark the schemes as shared.
The problem apparently being that the CI server user never actually opened the project in Xcode, thus causing the list command to hang because there were no available schemes for the user to build.
The times when it had intermittently worked were times after, logged in as the CI server user, I had opened the project in Xcode to test the build process, thus creating the necessary schemes. Wiping the CI server or refactoring/adding schemes would cause the build to break until the project was reopened in Xcode in desperation.
I had a similar issue when updating to Xcode 6.1 while using a newer version of subversion on the command line.
Disabling Source Control in Xcode Preferences should do the trick.
If that isn't an option you might try replacing the subversion implementation inside Xcode as I have done, using this technique: Use SVN 1.7 in XCode 4.3+
Basically that would be the following steps:
This assumes you already have SVN 1.7 installed to /opt/subversion, you can get it from WANdisco: http://www.wandisco.com/subversion/download#osx
Now open the Terminal and get an elevated shell using sudo -s.
Then, cd to inside the XCode.app package, to where the SVN binaries are.
Make a backup directory and move the old SVN files into it
bash-3.2# mkdir bup
bash-3.2# mv svn* bup/
Lastly, symbolically link the new files into the package:
bash-3.2# ln -s /opt/subversion/bin/svn* ./
That’s it!
I have the same problem on OS X 10.10 with XCode 6.4,just close XCode's Source Control to solved this issue:
run XCode
open Menu: XCode -> Preferences...
Click "Source Control" Tab and uncheck "Enable Source Control"

Resources