Why I can't build an Unity project by using Jenkins on MacOS?

I am trying to do End-to-End automation for an Unity IOS project. My aim is to automate the continuous integration process with attaching UIAutomation scripts as post build action. So from the time when a user do check his code in SVN and till we get test result of automation, everything will be automated.

Jenkins is installed on my local apple machine and running on local host.
Now I have automated build process through jenkins and at other end I have my shell script ready which will run C# scripts on build output.
When I use my shell script as post build action then I get error in running instrument command(written inside shell script) but if I run this script manually through terminal then it works fine:

FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL

Please let me know how can I run these commands successful.Help!

Yeah, I had that issue too. The problem is that the Unity editor requires access to the window server, since it insists on displaying a GUI even in batch mode. Thus, you can’t run it from a daemon process (which is the typical setup for Jenkins).

My hacky workaround was to use Applescript to launch a Terminal window and script it to run a secondary shell script (which in turns launches Unity, tails the log, launches xcodebuild, etc.).

Yep, it’s horrible! But I’ve been running this setup for several months now, and so far it hasn’t caused any problems, apart from making it annoying to work directly on the build machine when it keeps popping up new windows (but you normally shouldn’t be touching the build machine anyway). You can get fancy with output direction and tail -F to pass Unity’s log output back to Jenkins, which makes it mostly seamless.

It would be nice if Unity had a true headless mode. :slight_smile:

Chris, any more information you can provide on how you soled this problem ? I’m finding myself in a similar situation. When I install Jenkins to start as Daemon my build log on Jenkins does the following.

Started by user anonymous
Building in workspace /Users/Shared/Jenkins/Home/jobs/Unity_AutoBuildTest/workspace
Updating https://integration-pc/svn/Projects/AutoBuildTest at revision ‘2013-04-16T14:05:20.937 +0100’
At revision 3230
no change for https://integration-pc/svn/Projects/AutoBuildTest since the previous build
Piping unity Editor.log from /var/root/Library/Logs/Unity/Editor.log
[workspace] $ /Applications/Unity_4/Unity.app/Contents/MacOS/Unity -projectPath /Users/Shared/Jenkins/Home/jobs/Unity_AutoBuildTest/workspace -quit -batchmode -executeMethod AutomatedBuildScript.PerformIOSBuild
2013-04-16 14:05:23.149 Unity[52175:707] NSDocumentController Info.plist warning: The values of CFBundleTypeRole entries must be ‘Editor’, ‘Viewer’, ‘None’, or ‘Shell’.

Then hangs until the time-out kicks in and aborts the build.

When I uninstall and instead install it to run as user ‘Jenkins’ I get the following.

Started by user anonymous
Building in workspace /Users/Shared/Jenkins/Home/jobs/Unity_AutoBuildTest/workspace
Updating https://integration-pc/svn/Projects/AutoBuildTest at revision ‘2013-04-16T14:10:16.606 +0100’
At revision 3230
no change for https://integration-pc/svn/Projects/AutoBuildTest since the previous build
Piping unity Editor.log from /Users/Shared/Jenkins/Library/Logs/Unity/Editor.log
[workspace] $ /Applications/Unity_4/Unity.app/Contents/MacOS/Unity -projectPath /Users/Shared/Jenkins/Home/jobs/Unity_AutoBuildTest/workspace -quit -batchmode -executeMethod AutomatedBuildScript.PerformIOSBuild
Initialize mono
Mono path[0] = ‘/Applications/Unity_4/Unity.app/Contents/Frameworks/Managed’
Mono path[1] = ‘/Applications/Unity_4/Unity.app/Contents/Frameworks/Mono/lib/mono/2.0’
Mono config path = ‘/Applications/Unity_4/Unity.app/Contents/Frameworks/Mono/etc’
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,defer=y
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
2013-04-16 14:10:18.475 Unity[52351:707] NSDocumentController Info.plist warning: The values of CFBundleTypeRole entries must be ‘Editor’, ‘Viewer’, ‘None’, or ‘Shell’.

and then also hangs until the time-out kicks in.

Ask for the -nographics switch like the windows version has!

1 Like

I had some success using applescript with the following commands in a jenkins build shell script.

# here is some test code
osascript -e 'tell application "Terminal" to activate'	
osascript -e '	    
tell application "Terminal"
	do script "cd ~/" in window 1
	do script "whoami" in window 1
	do script "/path/to/Unity -projectpath /path/to/unity/project -quit -batchmode -executeMethod MyScript.PerformBuild" in window 1
end tell'

I also had to make sure the files of the unity installation had the same group as the jenkins user.

Jenkins by default installs as a LaunchDaemon, which means it has insufficient permissions to launch WindowsServer.

You’ll need to configure it as a LaunchAgent:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
sudo mv /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchAgents/org.jenkins-ci.plist

Then login as Jenkins and keep a session open.

If you don’t know the Jenkins password you can change it with:

sudo passwd jenkins

http://www.ourdailycodes.com/2013/09/building-unity3d-project-on-jenkins.html

“[…] solution is to create a slave node on Jenkins that will run Unity process […]”

The solution described in the link worked for me.

This link does not work , could you point to a working one. thank you

@ynedelin from the way back machine… if you were curious still.

http://web.archive.org/web/20130913134344/http://www.ourdailycodes.com/2013/09/building-unity3d-project-on-jenkins.html

1 Like

I’m not closely familiar with the topic, but a few questions so that maybe I know what to take back to the team at Unity:
What version of Unity are you using?
What is the command you use to try and start Unity on your server (and are you sure -batchmode -nographics doesn’t work on Mac)?
Have you looked into something like Unity3d?