Why is "xcodebuild: command not found" in this build script?

Hi I have the following in the root of my xcode project:

#!/bin/bash
xcodebuild -scheme target1 clean;
xcodebuild -scheme target1 archive;
xcodebuild -scheme target2 clean;
xcodebuild -scheme target2 archive;

However, this only executes the first line xcodebuild -scheme target1 clean; and then yields

...
** CLEAN SUCCEEDED **

xcodebuild: command not found
xcodebuild: command not found
xcodebuild: command not found

Disclaimer: I'm an absolute Mac OS X / Unix greenhorn.

Edit: Following kranteg's suggestion I added pwd to the script:

#!/bin/bash
pwd;
xcodebuild -scheme target1 clean;
pwd;
xcodebuild -scheme target1 archive;
pwd;
xcodebuild -scheme target2 clean;
pwd;
xcodebuild -scheme target2 archive;
pwd;

The output:

/Users/CKU/Programme/uraClient
=== CLEAN TARGET uraClient OF PROJECT uraClient WITH CONFIGURATION Debug ===

Check dependencies

<... lots of compiler messages about the clean ...>

** CLEAN SUCCEEDED **

/Users/CKU/Programme/uraClient
xcodebuild: command not found
/Users/CKU/Programme/uraClient
xcodebuild: command not found
/Users/CKU/Programme/uraClient
xcodebuild: command not found
/Users/CKU/Programme/uraClient

Edit 2: Replacing the pwd with echo $PATH yields a better result, now the script performs the first three xcodebuild commands before failing. However, the PATH variable seems to be unaffected by xcodebuild:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
=== CLEAN TARGET uraClient OF PROJECT uraClient WITH CONFIGURATION Debug ===

<... log messages ...>

** CLEAN SUCCEEDED **

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
=== BUILD TARGET uraClient OF PROJECT uraClient WITH CONFIGURATION Release ===

<... log messages ...>

** ARCHIVE SUCCEEDED **


The following commands produced analyzer issues:
    AnalyzeShallow uraClient/SQLiteLibrary/SQLiteManager.m
    AnalyzeShallow uraClient/URA/NSString+UrlEncoding.m
    AnalyzeShallow uraClient/Services/UraTripPredictionsProvider.m
    AnalyzeShallow uraClient/UtilityAppViewController/ViewController.m
    AnalyzeShallow uraClient/RNCryptor/RNDecryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNEncryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNOpenSSLCryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNOpenSSLDecryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNOpenSSLEncryptor.m
(9 commands with analyzer issues)
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
=== CLEAN TARGET uraAseag OF PROJECT uraClient WITH CONFIGURATION Debug ===

<... log messages ..>

** CLEAN SUCCEEDED **

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
xcodebuild: command not found
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools

With the help of kranteg & Opal I've come up with a working solution:

#!/bin/bash
/usr/bin/xcodebuild -scheme target1 clean archive;
/usr/bin/xcodebuild -scheme target2 clean archive;
/usr/bin/xcodebuild -scheme target3 clean archive;
<...>

Thanks again for the relentless community support, I would have given up otherwise :-)

Note: I've found that each scheme has a post-action step for the "Archive" action, that I had forgotten about:

xcrun -sdk iphoneos PackageApplication "$ARCHIVE_PRODUCTS_PATH/$INSTALL_PATH/$WRAPPER_NAME" -o "${HOME}/Desktop/${PRODUCT_NAME}.ipa"

This automatically creates .ipa files for Ad-Hoc deployment. Maybe this interfered with the original build script by changing a working directory. However, I don't understand why that would not register with the pwd and echo $PATH logging.

Why is coronavirus deadly for some, but harmless in others?, Why is 'x' the symbol for an unknown? In this short and funny talk, Terry Moore gives the Duration: 3:57 Posted: Mar 10, 2014 Noun. 1. why - the cause or intention underlying an action or situation, especially in the phrase `the whys and wherefores'. wherefore. reason, ground - a rational motive for a belief or action; "the reason that war was declared"; "the grounds for their declaration".

xcodebuild command will not work when Command Lines Tools is not setup for xcode.

Make sure that latest command line tools are selected (Under Xcode > Preferences > Locations)

Terry Moore: Why is 'x' the unknown?, President Donald Trump is about to cut the number of American troops stationed in Germany since the end of World War II. Definition of why (Entry 2 of 4) 1 : the cause, reason, or purpose for which know why you did it that is why you did it. 2 : for which : on account of which know the reason why you did it. why. noun. plural whys.

Make sure that you've installed Xcode's command line tools. Go to the Xcode->Preferences... Command and look for the panel that lets you download additional packages and documentation. IIRC, the command line tools can be installed from there.

Why is the US pulling troops out of Germany? | Germany, Why is Vedanta stock rallying after Rs 12,521 crore Q4 loss. PTI. While fundamentally, the company looks weak, the ongoing delisting progress  Why's definition, contraction of why is: Why's dinner so late? See more.

vedanta stock price: Why is Vedanta stock rallying after Rs 12,521 , Break-ups are never easy, but why do some people fight to win an ex back while others run a mile? The temptation to rekindle an old flame is  The question: "Why is [etc.]" is a question form in English: Why is the sky blue? Why is it that children require so much attention? Why is it [or some thing] like that? When that form is put into what is called indirect speech, it becomes: Please tell me why the sky is blue. Please tell me why children require so much attention.

Why is it so hard to forgive an ex?, Give me two hours, and I can do a dramatic reading of its entire genome. But much else about the pandemic is still maddeningly unclear. Why do  Sabrina Carpenter - Why (Official Lyric Video) - Duration: 2:57. Sabrina Carpenter 11,530,560 views. 2:57. The Girl and the Dreamcatcher - Make You Stay (Official Video) - Duration: 3:34.

Why the Coronavirus Is So Confusing, Don't get cocky. Nebula exclusive Les Miserables video: https://watchnebula.com​ Duration: 57:30 Posted: Apr 3, 2020 Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time.

Comments
  • Can you launch pwd before and after you run this script ? xcodebuild seems to change the working directory.
  • Perhaps xcodebuild makes change to your PATH variable. Can you add echo $PATH to your script instead of pwd ?
  • It should work if you use absolute path, so use /usr/bin/xcodebuild in your script. But I don't understand why it's not working.
  • You can pass multiple actions to single invocation: clean archive. What is the purpose of ; at the end of the command?
  • @kranteg & Opal: I've found a working solution by combining your suggestions. Many Thanks!
  • Possible that after the command failed it performed a "cd" back to it's original directory before the printworkingdirectory command was called.
  • Hi, the command line tools are installed and working, otherwise the first clean would fail as well. In fact, all commands from the script work when entered manually in the terminal.