Created
October 12, 2021 16:20
-
-
Save tatelax/02b5973688c039a937ca603fe6d8b642 to your computer and use it in GitHub Desktop.
A basic Jenkinsfile for Unity projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent { | |
node { | |
label 'windows' | |
} | |
} | |
environment { | |
VERSION = readFile(file: "game/Assets/StreamingAssets/version.txt").trim() | |
} | |
stages { | |
stage('Initialize Unity Project') { | |
steps { | |
buildName "${VERSION}+${GIT_COMMIT}" | |
writeFile(file: "game/Assets/StreamingAssets/version.txt", text: "${VERSION}+${BUILD_NUMBER}") | |
writeFile(file: "game/Assets/StreamingAssets/ActiveEnvironment.txt", text: "Main") | |
} | |
} | |
stage('Build Windows') { | |
environment { | |
UNITY_USERNAME = credentials('UNITY_USERNAME') | |
UNITY_PASSWORD = credentials('UNITY_PASSWORD') | |
BUILD_PROFILE = "WindowsMain" | |
UNITY_VERSION = "2020.3.14f1" | |
} | |
steps { | |
bat '"C:\\Program Files\\Unity\\Hub\\Editor\\%UNITY_VERSION%\\Editor\\Unity.exe" -quit -accept-apiupdate -batchmode -EnableCacheServer -cacheServerEndpoint 192.168.1.119:46711 -cacheServerNamespacePrefix GameName -cacheServerEnableDownload true -cacheServerEnableUpload true -logFile - -username %UNITY_USERNAME% -password %UNITY_PASSWORD% -projectPath "%WORKSPACE%/game" -executeMethod Scripts.Utils.BuildMaker.Editor.BuildCLI.Build -buildProfile "Assets/Settings/BuildProfiles/%BUILD_PROFILE%.asset"' | |
script { | |
// Verify that the build was created | |
// We do this because there are certain cases where Unity is not returning the correct exit code | |
if (!fileExists('game/Builds/Main/Windows/UnityPlayer.dll')) { | |
error('Unity build failed but returned a successful exit code. Scroll up in the logs a bit to find the error message. Try searching for "Error CS" if you\'re having trouble finding it.') | |
} | |
} | |
} | |
} | |
stage('Compressing Artifacts') { | |
steps { | |
script { | |
bat 'rmdir /S /Q game\\Builds\\Main\\Windows\\GameName_BackUpThisFolder_ButDontShipItWithYourGame' | |
bat '"C:\\Program Files\\7-Zip\\7z" a game/Builds\\Main\\Windows\\gamename_windows_main.zip .\\game\\Builds\\Main\\Windows\\* || exit /b 1' | |
} | |
} | |
} | |
stage('Archiving Artifacts') { | |
steps { | |
archiveArtifacts artifacts: 'game/Builds/Main/Windows/gamename_windows_main.zip', onlyIfSuccessful: true | |
// Delete the zip file because it has been archived and moved to Jenkins and because when we deploy to steam we dont want to include the zip | |
bat 'del /Q game\\Builds\\Main\\Windows\\gamename_windows_main.zip' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment