pipeline { //Definition of env variables that can be used throghout the pipeline job environment { // Github data String gitUrl = "git@github.com:GekoCloud/unity_build_demo.git" String gitCredentials = "jenkins-private-key" // set a PrivateKey credential if your repo is private // Unity tool installation UNITY_EXECUTABLE = "C:\\Path\\To\\Your\\Unity\\Version\\2020.3.16f1\\Editor\\Unity.exe" // Unity data UNITY_ID_EMAIL = credentials('jenkins-id-for-unity-email') UNITY_ID_PASSWORD = credentials('jenkins-id-for-unity-password') UNITY_ID_LICENSE = credentials('jenkins-id-for-unity-license') // Unity Build params BUILD_NAME = "Android-${currentBuild.number}" String buildTarget = "Android" String outputFolder = "CurrentBuild" //PARAMETERS DATA IS_DEVELOPMENT_BUILD = "${params.developmentBuild}" // Add other EnvVars here } //Options: add timestamps to job logs and limiting the number of builds to be kept. options { timestamps() buildDiscarder(logRotator(numToKeepStr: "10")) } //Variable inputs that modify the behavior of the job parameters { string(name: 'gitBranch', defaultValue: 'development', description: 'Set the branch.') booleanParam(name: 'developmentBuild', defaultValue: true, description: 'Choose the buildType.') } //Variable inputs that modify the behavior of the job agent { node { // Jenkins node to be used must have the label android label "android" } } //The steps necessary to generate the desired build stages { stage('Git Pull') { steps { echo "Git pull repo" script { try { git url: "${gitUrl}", branch: "${gitBranch}", credentialsId: "${gitCredentials}" } catch (e) { currentBuild.result = "FAILED" echo "JOB FAILED: The selected branch does not exists." } } } } stage('Activate License') { steps { script { echo "Activate License..." bat '%UNITY_EXECUTABLE% -nographics -projectPath %CD% -quit -batchmode -username %UNITY_ID_EMAIL% -password %UNITY_ID_PASSWORD% -serial %UNITY_ID_LICENSE%' } } } stage('Build Application') { steps { script { echo "create Application output folder..." bat 'mkdir %outputFolder%' echo "Buld App..." bat '%UNITY_EXECUTABLE% -projectPath %CD% -quit -batchmode -nographics -buildTarget %buildTarget% -customBuildPath %CD%\\%outputFolder%\\ -customBuildName %BUILD_NAME% -executeMethod BuildCommand.PerformBuilds' } } } } //Any action we want to perform after all the steps have succeeded or failed post { success { echo "Success :)" } failure { echo "failure :(" } always { script { echo "Return License..." bat '%UNITY_EXECUTABLE% -nographics -quit -batchmode -returnlicense -username %UNITY_ID_EMAIL% -password %UNITY_ID_PASSWORD%' } } } }