I am trying to set up a Jenkins server for automatic Unity builds.
Therefore I have written two (in my eyes) basically identical batch scripts.
Both scripts are run as build steps by Jenkins via an Execute Windows batch command
step using
Command: E:unityImport.bat
and after that a second Execute Windows batch command
step using
Command: E:unityBuild.bat
They both have the same beginning as I need to gather some file paths and in particular the project's unity version. So in both scripts I use exactly the same way of parsing and string splitting the project version. The only thing that is different between them is that the first one starts Unity and imports a dedicated unitypackage
(which hold the method to execute in the next step) into the project while the second one again starts Unity to perform the actual build (unfortunately it didn't work in one single go ... Unity seems to try to execute the method before the unitypackage
is imported).
However the second script always fails with a syntax error
")" cannot be processed syntactically here.
What I try to achieve is
Read out the content of the file
%WORKSPACE%ProjectSettingsProjectVersion.txt
SET /p TEST=<%WORKSPACE%ProjectSettingsProjectVersion.txt
The content of
%TEST%
usually looks like e.g.m_EditorVersion: 2019.3.4f1
and
ECHO. ProjectVersion.txt = %TEST%
looks likeProjectVersion.txt = m_EditorVersion: 2019.3.4f1
string split in order to only take the last part containing the version number
for %%x in (%TEST::= %) do ( SET "VALUE=%%x" SET "UNITY_VERSION=!VALUE:~0,-2!" )
so
%UNITY_VERSION%
usually contains e.g.2019.3.4
. I don't split more away because there are also Unity version with two digits like e.g.2018.4.18
string split on the
.
in order to only get the major release numberfor /f "tokens=1,2 delims=." %%a in ("%UNITY_VERSION%") do ( SET "A=%%a" SET "B=%%b" ) SET "UNITY_VERSION=%A%.%B%"
which results in
%UNITY_VERSION%
being e.g.2019.3
Finally search in all installed Unity versions if the required version is present
set "UNITY_FOLDER=" for /f "delims=" %%a in ('dir /b E:Unity\%UNITY_VERSION%*') do ( set "UNITY_FOLDER=%%a" )
after this we either found a valid Unity installation folder for the given version or not.
So here are the scripts.
Import (This works as expected)
@ECHO OFF
CLS
ECHO.
cd %WORKSPACE%
IF NOT EXIST %WORKSPACE%ProjectSettingsProjectVersion.txt (
EXIT 1
)
SETLOCAL ENABLEDELAYEDEXPANSION
SET /p TEST=<%WORKSPACE%ProjectSettingsProjectVersion.txt
ECHO. ProjectVersion.txt = %TEST%
for %%x in (%TEST::= %) do (
SET "VALUE=%%x"
SET "UNITY_VERSION=!VALUE:~0,-2!"
)
for /f "tokens=1,2 delims=." %%a in ("%UNITY_VERSION%") do (
SET "A=%%a"
SET "B=%%b"
)
SET "UNITY_VERSION=%A%.%B%"
ECHO. Project Unity Version = %UNITY_VERSION%
set "UNITY_FOLDER="
for /f "delims=" %%a in ('dir /b E:Unity\%UNITY_VERSION%*') do (
set "UNITY_FOLDER=%%a"
)
IF "%UNITY_FOLDER%"=="" (
EXIT 1
)
ECHO. Using Unity Version %UNITY_FOLDER%
ECHO. Running:
ECHO. E:Unity\%UNITY_FOLDER%EditorUnity.exe -quit -batchmode -projectPath %WORKSPACE% -logFile - -importPackage E:UnityBuildPackageAutoBuilder.unitypackage
E:Unity\%UNITY_FOLDER%EditorUnity.exe -quit -batchmode -projectPath %WORKSPACE% -logFile - -importPackage E:UnityBuildPackageAutoBuilder.unitypackage
IF NOT %errorlevel% equ 0 (
EXIT 1
)
EXIT 0
Build (This fails with a syntax error I will mark with REM HERE IT BREAKS! ...
which is not present in the actual script)
@ECHO OFF
CLS
ECHO.
cd %WORKSPACE%
IF NOT EXIST %WORKSPACE%ProjectSettingsProjectVersion.txt (
EXIT 1
)
SETLOCAL ENABLEDELAYEDEXPANSION
SET /p TEST=<%WORKSPACE%ProjectSettingsProjectVersion.txt
ECHO. ProjectVersion.txt = %TEST%
REM HERE IT BREAKS! The before echo is the last I see before getting the syntax error
for %%x in (%TEST::= %) do (
SET "VALUE=%%x"
SET "UNITY_VERSION=!VALUE:~0,-2!"
)
for /f "tokens=1,2 delims=." %%a in ("%UNITY_VERSION%") do (
SET "A=%%a"
SET "B=%%b"
)
SET "UNITY_VERSION=%A%.%B%"
ECHO. Project Unity Version = %UNITY_VERSION%
set "UNITY_FOLDER="
for /f "delims=" %%a in ('dir /b E:Unity\%UNITY_VERSION%*') do (
set "UNITY_FOLDER=%%a"
)
IF "%UNITY_FOLDER%"=="" (
EXIT 1
)
ECHO. Using Unity Version %UNITY_FOLDER%
...
I don't think the rest matters since as said What I see in the console it already breaks after e.g.
ProjectVersion.txt = 2019.3.4f1
")" cannot be processed syntactically here.
Does anyone see the mistake or is there maybe something with Jenkins that makes the second script fail with a syntax error even though as far as I see they are basically identical?
Question&Answers:os