In these guide, we explain how to setup Jenkins to automatically package and pre-compile an Unreal Engine project.
Install Jenkins Main docker
-
Copy the
docker-compose.yaml
file in your server :version: '3' services: jenkins-main: image: wesleypetit/jenkins:lts-jdk11 container_name: jenkins-main restart: unless-stopped ports: - "8080:8080" - "50000:50000" volumes: - jenkins_home:/var/jenkins_home # networks: # - nginx-proxy # networks: # nginx-proxy: # external: true volumes: jenkins_home:
It will automatically install several plugins : - P4 : Perforce Client plugin for the Jenkins SCM provider. - Matrix Authorization Strategy : Offers matrix-based security authorization strategies (global and per-project). - PostBuildScript : A plugin for the Jenkins CI to run several configurable actions after a build, depending on the build result. - Pre SCM BuildStep : This plugin allows build steps to be performed before the SCM step performs an action. - SCM Skip : Plugin adds functionality of preventing a Job to be built when a specific pattern ([ci skip]) in SCM commit message is detected. - Environment Injector : This plugin makes it possible to set an environment for the builds. - Discord Notifier : Discord Notifier provides a bridge between Jenkins and Discord through the built-in webhook functionality. - SAML : A SAML 2.0 Plugin for the Jenkins Continuous Integration server.
-
(Optional) If you want to use an anonymous account, pull
wesleypetit/jenkins:lts-jdk11
from portainer or run :sudo docker pull wesleypetit/jenkins:lts-jdk11
-
(Optional) If you install Nginx Proxy Manager, add a new proxy host to forward the port 8080 and add a new stream to forward the port 50000.
-
Deploy your container :
sudo docker-compose up -d
-
Finally, set up jenkins using this documentation.
-
Follow this documentation to disable building on the built-in node.
-
Install Windows on your build server.
-
In the windows agent, install several programs :
- Visual Studio with the appropriate workloads
- .NET Framework 3.5
- Epic Games Launcher
- The Unreal Engine version corresponding to your project.
- Java SDK 11
- Jenkins
ℹ️ I write a small script to install Unreal Engine prerequisites (Visual Studio, .NET core, JDK11 and Jenkins). Only the Epic Games launcher is not automatically installed, as it does not provide an official package.
-
Now, go
Manage Jenkins > Nodes
in your Jenkins Main Dashboard. -
Click on add
New Node
, enter a node name (e.g windows-unreal-engine) and pickPermanent Agent
. -
Specify the
Remote root directory
dedicated to Jenkins an click on Save. -
Now, click on the node and execute the given command in the windows agent.
We use Auth0, because it proposes a free tier without credit card that is limited to 7500 active user.
-
Create an account on Auth0, it will unify authentication for Helix and other services. Complete all steps depending on your location.
-
In Auth0, create a
Regular Web Application
without specifying the technology. It will allow Jenkins to use Auth0 for Authentication. -
Now, go to Applications > <YOUR_NEWLY_APPLICATION_CREATED> > Settings and keep aside your
Client ID
andDomain
, as it will be needed for Jenkins settings. -
In
Allowed Callback URLs
, add <YOUR_JENKINS_URI>/securityRealm/finishLogin -
In
Allowed Logout URLs
, add <YOUR_JENKINS_URI>. -
Scroll and open
Advanced Settings
section and click onEndpoints
. -
Copy the
SAML Metadata URL
field and open it in your browser. It's your IdP Metadata file needed for Jenkins settings. -
Click on Save Changes.
-
Now, go back to your Jenkins dashboard.
-
Go in
Manage Jenkins > Security
and changeSecurity Realm
to SAML 2.0. -
Copy and paste your IdP Metadata file in the appropriate field.
-
Set the
Username Attribute
to nameid andEmail Attribute
to email. -
Add your IdP logout url (e.g https://<YOUR_AUTH0_DOMAIN>/v2/logout?client_id=<YOUR_AUTH0_CLIENT_ID>&returnTo=<YOUR_JENKINS_URI>).
-
Click apply and test on another browser. The idea is to modify settings without losing access.
-
Go to
Manage Jenkins > Credentials
and click on(global)
. -
Click on Add Credentials.
-
Enter your P4PORT (without the ssl prefix).
-
If your helix core server use ssl connection, enable SSL connection checkbox and add your server fingerprint in the Trust field. Here is a command to get your server fingerprint :
p4 -u <YOUR_USER_NAME> -p <YOUR_P4_PORT> trust -l
-
Enter your jenkins username and generate a long-lived login ticket :
p4 -u <YOUR_USER_NAME> -p <YOUR_P4_PORT> login -ap
-
Click on Test Connection to debug your credentials then click on Save.
In these guide, we explain how to setup a Jenkins pipeline to automatically package an Unreal Engine project and (optionally) send a discord notification containing a download link to the package. These guide is heavily inspire by Patrice Vignola guide, I updated the instructions with Unreal Engine 5.
-
Go to
Dashboard > New Item
to create a new project. -
Enter a name and pick Freestyle project.
-
Select Perforce Software in the Source Code Management section.
-
Pick a Perforce Credentials, change the
Workspace behavior
to Streams and define on which stream you want to package inStream Codeline
. -
(optional) Setup build periodically for build triggers. In our case, we package the game every working day at 8AM (e.g H 8 * * 1-5).
-
Enable
Inject environment variables to the build process
and add these fields in the Properties Content field :PROJECT_NAME=<YOUR_PROJECT_NAME> BUILD_CONFIG=BuildCookRun PLATFORM=Win64 CONFIG=Shipping ARCHIVE_DIRECTORY=%WORKSPACE%\Build ARTIFACT_NAME=%PROJECT_NAME%_Win_CL-%P4_CHANGELIST%_ID-%BUILD_ID% UE_REBUILD_BAT=C:\Program Files\Epic Games\UE_5.3\Engine\Build\BatchFiles\RunUAT.bat
Here is a full explanation of each fields : - PROJECT_NAME : It corresponds to your .uproject filename, we expect to find it under the workspace root folder. - BUILD_CONFIG : Unreal automation commands (BuildCookRun, BuildGame...). You can find more using the command
<YOUR_ENGINE_FOLDER>\Build\BatchFiles\RunUAT.bat -List
. - PLATFORM : Platforms to build, join multiple platforms using + (e.g Win64+PS4+XboxOne). - CONFIG : Configurations to build, join multiple configurations using + (e.g Development+Test). - ARCHIVE_DIRECTORY : Directory to archive the builds to. - ARTIFACT_NAME : Final build name. In our case, we add the changelist and the jenkins build id in the name (e.g AwesomeProject_Win_CL-100_ID-0). - UE_REBUILD_BAT : Path to RunUAT.bat file corresponding to your Unreal Engine version.
-
In the Builds Steps section, click on
Add Build Step
and pickExecute Windows batch command
. -
Add the following command to package your game :
CALL "%UE_REBUILD_BAT%" %BUILD_CONFIG% -project=%WORKSPACE%\%PROJECT_NAME%.uproject -Platform=%PLATFORM% -configuration=%CONFIG% -archive -archivedirectory="%ARCHIVE_DIRECTORY%" -clean -cook -skipstage -build -pak -package -makebinaryconfig -distribution -SkipCookingEditorContent -ForceMonolithic -NoP4 -NoSubmit IF %ERRORLEVEL% NEQ 0 (EXIT %ERRORLEVEL%)
ℹ️ For package arguments, the official Unreal Automation Tool documentation is an good overview. If you need more information check out Botman repository.
-
Add a new Windows batch command to rename the package folder :
CALL rename Build\Windows "%ARTIFACT_NAME%"
-
Add a new Windows batch command to zip the package folder :
CALL "%UE_REBUILD_BAT%" ZipUtils -archive="%WORKSPACE%\%ARTIFACT_NAME%.zip" -add="%ARCHIVE_DIRECTORY%" -compression=9 IF %ERRORLEVEL% NEQ 0 (EXIT %ERRORLEVEL%)
-
In the Post-build actions section, click on
Add post-build action
and pickArchive the artifacts
. -
To add the generated build as an artifact, change the files to archive field to :
*.zip
-
Click on Advanced and enable
Archive artifacts only if build is successful
.
-
Follow the Introduction to Webhooks guide to generate a Webhook URL.
-
Edit your jenkins pipeline.
-
In the Post-build actions section, click on
Add post-build action
and pickDiscord Notifier
. -
Enter your Webhook URL.
-
Click on Advanced and enable
Enable URL linking
to redirect the discord message to the jenkins build. -
Save, test and your are done !
In these guide, we explain how to setup a Jenkins pipeline to automatically precompile and submit the DLLs in Perforce. Artists/designers will receive the DLLs and no longer need to compile. Optionally, we will send a discord notification on failed build. These guide is heavily inspired by the Unreal Community Wiki, I updated the instructions with Unreal Engine 5.
Here is the complete workflow :
- Coders make code changes and submit them to the coder stream.
- Jenkins monitors the mainline stream, syncs to the latest changes, builds the project, and submits the generated DLLs to the mainline stream.
- Artists/designers sync the mainline stream to receive the updated DLLs.
On the technical aspect, you need two virtual stream : - coder : inherits from main but excludes all Binaries folders. - jenkins-binaries-compilation : inherits from main but excludes all Content folders since it won't need it.
Here is the stream hierarchy :
-
Create a virtual stream for coders :
-
In the
Advanced
tab, add the following paths and adapt it to your project :share ... exclude Binaries/... exclude Plugins/AwesomePlugin/Binaries/...
-
Create a virtual stream for jenkins :
-
In the
Advanced
tab, add the following paths and adapt it to your project :isolate ... exclude Content/... exclude Plugins/AwesomePlugin/Content/... share Binaries/... share Plugins/AwesomePlugin/Binaries/...
-
In Jenkins home page, go to
Dashboard > New Item
to create a new project. -
Enter a name and pick Freestyle project.
-
Select Perforce Software in the Source Code Management section.
-
Pick a Perforce Credentials, change the
Workspace behavior
to Streams and set the jenkins binaries stream inStream Codeline
. -
Under polling build filters, click on
Add new build filter
and selectExclude changes outside Java pattern
. -
With the following pattern, a build we be triggered only when a changelist contains a code file (.h or .cpp) :
//your_depot_path/main/.*\.cpp //your_depot_path/main/.*\.h
-
(optional) Enable Poll SCM for build triggers, Jenkins will scan the current workspace and compare with the server to trigger or not a build. In our case, we set the poll frequency to every 30 minutes (e.g H/30 * * * *).
-
Enable
Inject environment variables to the build process
and add these fields in the Properties Content field :PROJECT_NAME=<YOUR_PROJECT_NAME> BUILD_CONFIG=BuildEditor PLATFORM=Win64 CONFIG=Development UE_REBUILD_BAT=C:\Program Files\Epic Games\UE_5.3\Engine\Build\BatchFiles\RunUAT.bat
Here is a full explanation of each fields : - PROJECT_NAME : It corresponds to your .uproject filename, we expect to find it under the workspace root folder. - BUILD_CONFIG : Unreal automation commands (BuildCookRun, BuildGame...). You can find more using the command
<YOUR_ENGINE_FOLDER>\Build\BatchFiles\RunUAT.bat -List
. - PLATFORM : Platforms to build, join multiple platforms using + (e.g Win64+PS4+XboxOne). - CONFIG : Configurations to build, join multiple configurations using + (e.g Development+Test). - UE_REBUILD_BAT : Path to RunUAT.bat file corresponding to your Unreal Engine version.
-
In the Builds Steps section, click on
Add Build Step
and pickExecute Windows batch command
. -
Add the following command to compile your game :
CALL "%UE_REBUILD_BAT%" %BUILD_CONFIG% -platform=%PLATFORM% -configuration=%CONFIG% -project="%WORKSPACE%\%PROJECT_NAME%.uproject" -WaitMutex -FromMsBuild -notools -ForceCompile IF %ERRORLEVEL% NEQ 0 (EXIT %ERRORLEVEL%)
ℹ️ For package arguments, the official Unreal Automation Tool documentation is an good overview. If you need more information check out Botman repository.
-
Follow the Introduction to Webhooks guide to generate a Webhook URL.
-
Edit your jenkins pipeline.
-
In the Post-build actions section, click on
Add post-build action
and pickDiscord Notifier
. -
Enter your Webhook URL.
-
Enable
Send only failed
. -
Click on Advanced.
-
Enable
Enable URL linking
to redirect the discord message to the jenkins build and enableSend log file to discord
. -
Disable
Enable version info in footer
andEnable artifact list
.
-
In the Post-build actions section, click on
Add post-build action
and pickPerforce: Publish assets
. -
Pick a Perforce Credentials, change the
Workspace behavior
to Streams and set the jenkins binaries stream inStream Codeline
. -
Change the
Publish Options
to Submit change. -
Enable
Only publish on build success
andReopened files
. These options makes sure you submit only correct binaries and that Jenkins checkout for the next build. -
Set a
Purge Revisions
(e.g 5) to only stores the last n revisions in Perforce. -
Click on Advanced and add the following paths :
//your_depot_path/jenkins-binaries-compilation/Binaries/... //your_depot_path/jenkins-binaries-compilation/AwesomePlugin/Binaries/...
⚠️ Submit with publish paths ignore p4ignore files. -
Click on
Save
.
- Jenkins Docker Hub Page
- Jenkins Plugin P4
- Jenkins Plugin Matrix Authorization Strategy
- Jenkins Plugin PostBuildScript
- Jenkins Plugin Pre SCM BuildStep
- Jenkins Plugin SCM Skip
- Jenkins Plugin Environment Injector
- Jenkins Plugin Discord Notifier
- Jenkins Plugin SAML
- Jenkins Setup
- Disable building on the built-in node
- Setting Up Visual Studio for Unreal Engine
- Auth0
- Ticket-based authentication
- Patrice Vignola packaging automation guide
- Unreal Automation Tool Overview
- Unreal Automation Arguments
- Introduction to Discord Webhook
- Precompile an Unreal Project using Jenkins