bash: xcodebuild: command not found while setting up iOS (swift) CI/CD pipeline on bitbucket?
Asked by Akash Ashok Kondekar:

Hello,

I am a newbie on CI/CD bitbucket integration stuff. When I was trying to execute any command related to **xcodebuild,** (such as clean, build, etc) by specifying it in yml file, it threw me an error "bash: xcodebuild: command not found command not found".

I tried multiple solutions for it but not a single command/Path works for me hence if I get help related to that then that will be helpful or else If I get step-by-step Documentation related to CI/CD iOS with bitbucket integration will also work.

FYI: Checked with the correct Path and required xcodebuild to be in the same directory or not and found they both were at the same level.


Answers:
author: Theodora Boudale
body: Hi [@Akash Ashok Kondekar](/t5/user/viewprofilepage/user-id/3993249),

MacOS Runners use Bash to run pipeline steps on your MacOS machine (host device), so the builds do not run in Docker containers.

What the runner will do for each step is clone the repo on your machine (unless you have disabled cloning in your bitbucket-pipelines.yml file) and then execute the commands from the step's script. The runner will try to empty the build directory after each step.

If a certain tool is installed on your MacOS machine and you can use it from bash, it should be possible to use it with a MacOS Runner.

If you try the following:

* open a new terminal on your Mac
* clone the repo you want to run builds for
* change directory to the clone you created
* execute the commands from your bitbucket-pipelines.yml file's script

are you then able to run the failing command this way?

Does the command **which xcodebuild** return any output?

Kind regards,  
Theodora

comments: author: Akash Ashok Kondekar
body: Thanks for the reply, [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

Unfortunately, I am still facing the same issue. Posting screenshots that might help you to understand where I am failing at:

1. yml file: It started failing from line 18, i.e. xcodebuild clean... command

![Screenshot_2023-07-10_at_4.04.44_PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/267722iFFC39BCD3117A875/image-size/large?v=v2&px=999 "Screenshot_2023-07-10_at_4.04.44_PM.png")

2. Output that I can see on bitbucket pipeline console:

![Screenshot_2023-07-10_at_4.05.54_PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/267724i466026E5D857CAD3/image-size/large?v=v2&px=999 "Screenshot_2023-07-10_at_4.05.54_PM.png")

As I said earlier, I had already committed and can see **xcodebuild** at the same level directory level where in my installing my pods.


author: Theodora Boudale
body: Hi [@Akash Ashok Kondekar](/t5/user/viewprofilepage/user-id/3993249),

Thank you for the info.

I can see from both screenshots that you are running this Pipelines build on our own infrastructure. You mentioned in the title iOS pipeline, so I thought you were using a MacOS Runner (this is why I was talking about MacOS Runners in my previous post).

Pipelines that run in Atlassian's infrastructure currently run on a Kubernetes cluster of Linux Docker hosts. I believe that it is not possible to run xcodebuild on a computer that is not a MacOS, so I don't think you'll be able to run this build on our own infrastructure.

If you have a MacOS that you can use to run builds, you can set up a MacOS runner on that machine and run builds there:

* <https://support.atlassian.com/bitbucket-cloud/docs/set-up-runners-for-macos/>

The builds will run on your MacOS, but you'll still be able to view the logs on the Bitbucket website on the Pipelines page of the repo. Additionally, you won't be charged for the build minutes used by your self-hosted runner.

You can see here the **Supported platforms** and **Minimum Requirements** for runners:

* <https://support.atlassian.com/bitbucket-cloud/docs/runners/>

Please feel free to let me know if you have any questions.

Kind regards,  
Theodora


author: Akash Ashok Kondekar
body: Thanks, [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)  

Here's a summary of the actions we've tried so far:

* Clearing Derived Data
  * We attempted to resolve any cached or corrupted build artifacts by clearing the derived data for your Xcode project.

<!-- -->

* Cleaning Build
  * To ensure there are no old artifacts causing conflicts, we performed a clean build by holding the "Option" key and selecting "Clean Build Folder" in Xcode.

<!-- -->

* CocoaPods Version
  * We ensured that we are using the latest version of CocoaPods by running "gem install cocoapods" and updating the pods with "pod update".

<!-- -->

* Xcode Version
  * We confirmed that we are using the latest stable version of Xcode to avoid any bugs or compatibility issues.

<!-- -->

* Review Pod Configuration
  * We reviewed the configurations in the Xcode project after installing the pods to ensure correct integration with the main app target.

<!-- -->

* Swift Code
  * We reviewed your Swift code for any syntax errors or issues that might be causing the compiler to fail.

<!-- -->

* Pod Dependency Conflicts
  * We checked for pod dependency conflicts and updated or removed specific pod versions to resolve any conflicts.

<!-- -->

* System and Xcode Compatibility
  * We verified that your macOS version and Xcode version are compatible with the Swift version and the pods we are using.

<!-- -->

* Verify Signing and Capabilities\*We ensured that the signing and capabilities are correctly configured for the 'DailyMentor' target. This includes checking provisioning profiles, certificates, and any necessary entitlements.

Despite implementing the above steps, we still encounter the same error: ie. "**BUILD FAILED** The following build commands failed: SwiftEmitModule normal arm64 Emitting\\ module\\ for\\ DailyMentor (in target 'DailyMentor' from project 'DailyMentor') (1 failure)"  

PFA screenshots.  

![Screenshot_2023-07-18_at_4.04.09_PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/269529i868DF3EC435A6AC8/image-size/large?v=v2&px=999 "Screenshot_2023-07-18_at_4.04.09_PM.png")![Screenshot_2023-07-18_at_4.03.00_PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/269530i53C47C9260849EBE/image-size/large?v=v2&px=999 "Screenshot_2023-07-18_at_4.03.00_PM.png")  

I am not sure now what I am missing here.


author: Theodora Boudale
body: Hi [@Akash Ashok Kondekar](/t5/user/viewprofilepage/user-id/3993249),

Are you using a MacOS runner now for the build?

Is the issue reproducible outside of the runner, if you clone the repo and run the commands from your yml file's script?  

I don't know what exactly the issue is as I'm not familiar with the tools you are using. If the issue is also reproducible outside the runner, I would suggest reaching out to a forum dedicated to xcode support.

Kind regards,  
Theodora


author: Akash Ashok Kondekar
body: Hello [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

Yes, we are now using MacOS runners. We tried without runner first and there we were getting the "Xcode command not found" error. Then as you mentioned a guided setup for the runner was, we did try that and after that, we are now started getting this issue.

" BUILD FAILED The following build commands failed: SwiftEmitModule normal arm64 Emitting\\ module\\ for\\ DailyMentor (in target 'DailyMentor' from project 'DailyMentor') (1 failure)

![Screenshot_2023-07-18_at_4.03.00_PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/269573iF94A5FBA3C72FFE9/image-size/large?v=v2&px=999 "Screenshot_2023-07-18_at_4.03.00_PM.png")![Screenshot_2023-07-18_at_4.04.09_PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/269572iC4116840684118C9/image-size/large?v=v2&px=999 "Screenshot_2023-07-18_at_4.04.09_PM.png")

So to summarise it:

**MacOS Runner** **:** Yes, we are using a MacOS runner for the build process. The build is being performed on a self-hosted MacOS runner provided by Atlassian Pipelines.

**Reproducibility** **:** We have tested the build commands from the yml file's script on our local development environment, and the issue is not reproducible there. The build process works as expected when executed locally.

**Runner Environment** **:** Considering that the build failure is specific to the runner environment, we suspect that there might be some differences or limitations in the runner setup that are causing the SwiftEmitModule failure.

**Dependency on Runner Environment** **:** As we have confirmed that the issue is not occurring outside of the runner environment, it indicates that the problem might be related to the specific runner's configuration or resources.


author: Patrik S
body: Hello [@Akash Ashok Kondekar](/t5/user/viewprofilepage/user-id/3993249)

Since the macOS runners are executed in a shell session, could you please try executing the same exact commands you have in your pipeline script, but in a shell session outside the runner?

You can open a new terminal window on the same machine that is hosting the runner, and try executing the **xcodebuild**command directly in that terminal to check if the same error happens. This will help us diagnose whether the issue lies within the host environment itself or on the runner.

Also, I found the following Stackoverflow thread reporting an error similar to the one you are receiving, which might be of help :

* <https://stackoverflow.com/questions/73833458/swiftemitmodule-normal-arm64-emitting-module-for-yogakit-in-target-yogakit>

Thank you, [@Akash Ashok Kondekar](/t5/user/viewprofilepage/user-id/3993249) !

Patrik S


Tags: bitbucket-cloud

cloud