Hello,
I’m trying to set up a Jenkins/continuous integration setup with unity. I’m having trouble figuring out how to run the
-executeMethod command to run the actual build script. And since Jenkins is starting the script from outside unity, I have no clue if the script is running correctly, or if my code in the script is coded wrong. What I basically want the script to do is create a build of my project and load the correct scene. Here is the code I was working with in my screen and the windows batch command line I used to start everything. I ended up using angrybots as a test project.
"C:\Program Files (x86)\Unity\Editor\Unity.exe" -projectPath "C:\Projects\svn_repos" -executeMethod MyEditorScript.Start
This is the code in my script, placed in the asset/editor folder of my project:
using UnityEditor;
using UnityEngine;
using System.Collections;
public class MyEditorScript: MonoBehaviour
{
static void Start()
{
string[] scenes = {"Assets/AngryBots.unity" };
BuildPipeline.BuildPlayer(scenes, "StandaloneWindows64", BuildTarget.StandaloneWindows64, BuildOptions.None);
}
}
Is my batch command line correctly written? or is my MyEditorScript.CS written wrong?
I have this odd feeling that the second parameter for BuildPlayer is wrong…the unity documentation sites says, its a locationpathname, to what? a complied verison of my project, like an exe? or are they talking about locationpathname to the scene I’m trying to load?
Should I just use Application.LoadLevel to load my scene instead? then use the BuildPipeline.BuildPlayer?
1 Like
First off, this thread caught my eye since I deal with a lot of automated builds/deployments at my day job. I don’t have pro yet but I am very happy with the inclusion of scripting any part of unity. So, kudos to you and your CI-ness.
Anyway, it looks like the parameter “locationPathName” is the output of the built assets which includes the .exe part of the filename. I assume that the resources folder would be created at the same path. What I don’t know is that you need include the full path + filename:
BuildPipeline.BuildPlayer(scenes, “C:\Build\AngryBotsWindows.exe”, BuildTarget.StandaloneWindows64, BuildOptions.None);
I don’t have pro so I can’t test this out but it seems very similar to MSBuild type parameters.
@ Unity - Scripting API: BuildPipeline.BuildPlayer
2 Likes
Thanks for the fast reply roguemonkey. I got the Jenkins to run the script and build the correct project and one of the senior programmers, figured out that you do have to add .exe, .unity3d etc to the end of the second parameter like you did up there to actually make it work. So thank you very much.
Now, I’m trying to figure out how to run the new .exe file with command line so I can make it do stuff in the game(like click around the scene or level to make sure stuff doesn’t crash). I’m going to create a new post about that since, its a problem that somewhat different then this one. I would love if you could comment or provide some advice on that problem.
1 Like
Hey Nemox, I know its yonks since you posted but figured it cant hurt to ask.
We’re currently looking at getting a CI setup sorted out for iOS projects. However when attempting this with jenkins we get errors at build time where it looks like it cant connect to the WindowServer (from what I’ve dug up this is because unity doesnt have a proper headless mode and needs the WindowServer to run it while building) I’m currently trying to find a way around this, alongside trying other CI solutions, but no joy yet.
Did you have this issue when you were setting up your Jenkins setup? and if so how did you overcome it?
Thanks.
1 Like
You need to run in batch mode (-batchmode -quit):
here’s our Jenkins command line (run via an ‘execute shell’ block in the jenkins build config), this is for our iOS build:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -projectPath “${WORKSPACE}” -executeMethod Build.Build_iOS_Device -quit -logFile /dev/stdout
obviously alter the path to the unity executable and the build method appropriately.
2 Likes
I made a complet Script for building app with Unity
check it out Unity Generic auto build – Farges Maelyss
2 Likes