How to pass extra build flags to xcodebuild

How do I pass variables such as SWIFT_FLAGS or PREPROCESSOR_DEFINITIONS to xcodebuild using the Xcode archive step? We use those to build against different environments.

1 Like

If you use the Xcode Archive step that has an input Additional options for xcodebuild call. You can add additional flags there.

I tried with SWIFT_FLAGS="-D TESTING" but it doesn’t seems to be working

What’s the xcodebuild .. in the log? The full xcodebuild command is printed in the step’s log.

$ set -o pipefail && xcodebuild "-workspace" "Harmony.xcworkspace" "-scheme" "Harmony" "-configuration" "Release" "CODE_SIGN_IDENTITY=iPhone Distribution: Future Workshops Limited" "clean" "archive" "-archivePath" "/var/folders/90/5stft2v13fb_m_gv3c8x9nwc0000gn/T/__archive__735067517/HA-Harmony-241.xcarchive" "SWIFT_FLAGS=-D TEST_INTERNAL" | xcpretty

It seems to be OK - why do you think it does not work? Also, what happens if you run the command locally on your Mac?

Note: No need for pipefail and xcpretty on your Mac if you don’t have pretty installed already, this should do the same:

xcodebuild "-workspace" "Harmony.xcworkspace" "-scheme" "Harmony" "-configuration" "Release" "CODE_SIGN_IDENTITY=iPhone Distribution: Future Workshops Limited" "clean" "archive" "SWIFT_FLAGS=-D TEST_INTERNAL"

I believe my problem is between the chair and the screen - It should be OTHER_SWIFT_FLAGS not SWIFT_FLAGS.

No problem at all :slight_smile:

Just to be sure, specifying that (OTHER_SWIFT_FLAGS) the same way (Additional options for xcodebuild call input of the archive step) does work, right?

yes using OTHER_SWIFT_FLAGS as you suggested works. The problem was just the name of the env variable.

1 Like

Awesome, thanks @FWFabio! :blush: