Copying code and creating build by executing shell script on MacOS(Ventura) through API fails to copy the code due to permission errors

23 views Asked by At

I have an api which executes a shell script on a MacOS(Ventura) server. The script starts the execution without issues. The script's function is to copy the code of an iOS and Android app and create build. But while creating builds for both iOS and Android , the Xcode and android commands have to access different folders and files like Derived Data folder , and on Android gradle folder. Also have to create cache folders.But it fails to access those due to permission error. When the same script is run directly by the MacOS user it works perfectly fine but whenever it is executed through the API, the build process fails.

Here is the code, through which the script execution is triggered :

shell_exec('xyz.sh');

Some of the errors include :

Also the copied source code when opened in Xcode gives error to UNLOCK the project file and when unlocking it says "You do not have the permission to edit"

cp: /Users/username/Library/MobileDevice/Provisioning Profiles/5f15678-6bb8-4d5-adb-ad51b97fe926.mobileprovision: Permission denied

Couldn't create workspace arena folder '/var/root/Library/Developer/Xcode/DerivedData/Motto_Mobile_New-gxwkwneokwqfthcucsmectjkjgqq': You don’t have permission to save the file “Motto_Mobile_New-gxwkwneokwqfthcucsmectjkjgqq” in the folder “DerivedData”.

Exception in thread "main" java.io.FileNotFoundException: /var/root/.gradle/wrapper/dists/gradle-7.3.3-bin/6a41zxkdtcxs8rphpq6y0069z/gradle-7.3.3-bin.zip.lck (Permission denied)

Like I wrote above, all works fine when the script is run directly on the System using the terminal.

Please let me know if there is any solution.

EDIT - Also found that this line :

echo "$BUILD_KEYCHAIN_PW" | sudo -S xcode-select -s /Applications/Xcode.app/Contents/Developer

when executed gives this error :

Password:Sorry, try again. Password: sudo: no password was provided sudo: 1 incorrect password attempt

The above error is seen in the logfile generated.

0

There are 0 answers