diff --git a/.changelog/33.changed.md b/.changelog/33.changed.md new file mode 100644 index 0000000..55585e5 --- /dev/null +++ b/.changelog/33.changed.md @@ -0,0 +1 @@ +Updated the unreal feature to run Setup.ps1 from UEProjectBootStrap only when the jenkins job ID is different diff --git a/src/generator/features/python.py b/src/generator/features/python.py index 96d3113..2b80599 100644 --- a/src/generator/features/python.py +++ b/src/generator/features/python.py @@ -6,7 +6,7 @@ * executePythonScript which will execute an executable in the virtual environment's Scripts folder """ -from typing import Any, Dict, Type +from typing import Any, Dict, Optional, Type from pydantic import Field, ValidationInfo, model_validator @@ -16,11 +16,12 @@ class PythonConfig(FeatureConfig): """Configuration for the pipeline properties.""" - venv_activation_script_path: str = Field( + venv_activation_script_path: Optional[str] = Field( + default=None, description=( "The path to the virtual environment activation script." "This must point to a script that can be sourced to activate the virtual environment." - ) + ), ) venv_folder: str = Field( description="The path to the virtual environment folder after it has been created by executing venv_activation_script_path.", diff --git a/src/generator/features/unreal.py b/src/generator/features/unreal.py index b5ce103..eff59f9 100644 --- a/src/generator/features/unreal.py +++ b/src/generator/features/unreal.py @@ -1,6 +1,7 @@ """This feature works by using Buildgraph in an Unreal Engine project. -It requires that you also use PyScripts https://github.com/TheEmidee/UEPyScripts, -which can be inside your game project or in a separate folder. +It requires that you use +* UEProjectBootStrap : https://github.com/TheEmidee/UEProjectBootstrap +* PyScripts https://github.com/TheEmidee/UEPyScripts In a nutshell, this is how this feature works: 1. Before generating any text to output in the Jenkinsfile, this feature will run the @@ -26,6 +27,9 @@ it will read them from the shared storage directory. 5. When jenkins is done, the shared storage directory is cleaned up at the end of the pipeline to avoid cluttering the disk with old results, and to make sure that there are no artifacts left from previous jobs. + +Note that the script Setup.ps1 created by UEProjectBoostrap will be called when needed before any unreal task is executed +to ensure that all the requirements (such as Python and the required moduldes) are installed on the machine. """ import subprocess diff --git a/src/generator/templates/unreal.mako b/src/generator/templates/unreal.mako index 7e0daa4..33fd7f0 100644 --- a/src/generator/templates/unreal.mako +++ b/src/generator/templates/unreal.mako @@ -102,7 +102,7 @@ def cleanup() { projectCheckout() stage ( "Cleanup" ) { - activatePythonEnvironment() + runSetupScript() def build_tag = getSanitizedBuildTag() executePythonScript( "ue-ci-cleanup", <%text>"--build_tag=${build_tag}" ) @@ -121,7 +121,7 @@ def postCleanupTasks() { } def preBuildGraphTasks() { - activatePythonEnvironment() + runSetupScript() fileOperations( [ @@ -142,6 +142,28 @@ def postBuildGraphTasks( String taskName ) { % endif } +def runSetupScript() { + <%text>def setupJobIdFile = "${WORKSPACE}/Saved/JenkinsSetupScriptJobId.txt" + def currentBuildTag = getSanitizedBuildTag() + + def shouldRunSetup = true + + if (fileExists(setupJobIdFile)) { + def existingTag = readFile(setupJobIdFile).trim() + if (existingTag == currentBuildTag) { + <%text>echo "Setup already ran for build tag '${currentBuildTag}'. Skipping." + shouldRunSetup = false + } + } + + if (shouldRunSetup) { + <%text>echo "Running setup script for build tag '${currentBuildTag}'..." + pwsh 'New-Item -ItemType Directory -Force -Path Saved' + writeFile file: setupJobIdFile, text: currentBuildTag + <%text>pwsh script: "${WORKSPACE}/Setup.ps1 -BuildMachine" + } +} + def getSanitizedBuildTag() { return BUILD_TAG.replace(" ", "_") }