Search Results for

    Show / Hide Table of Contents

    Build mods with a self-hosted Jenkins setup

    中文 | English

    Use Jenkins to schedule a local build manifest on your own Windows build machine. The official mod repository uses GitHub Actions Build modpack.

    1. Install the service and complete setup

    1. Install a Java version supported by your Jenkins LTS, then run its Windows MSI. Choose the installation directory. Use a local or domain account with Log on as a service permission, then select the Java home and port. Jenkins Windows installation
    2. Check that Jenkins is running in Windows Services. Use Restart there after changing the service configuration. Open the selected local port in a browser. The default is http://localhost:8080.
    3. On Unlock Jenkins, read the initialAdminPassword file from the shown location and enter it. Choose Install suggested plugins or Select plugins to install. Create the first administrator and open Jenkins. The Pipeline below calls Unity directly. Install other plugins as needed.

    2. Prepare the build machine and manifest

    1. Install Git, Git LFS, the SDK's Unity version, and the target platform modules. Verify that the Jenkins service account can read the project and run Unity. Put the full path to the matching Unity.exe in the worker's UNITY_EXE environment variable.
    2. Commit the ModPackageBuildPiplineData asset and CI/ModBuild.json in the Unity project. Follow the manifest example and keep StandaloneWindows64 as its platform and Build/Ship/Windows as its destination. Begin with an empty output directory.
    3. Add Assets/Editor/CiModBuild.cs to the Unity project with this -executeMethod entry point. The caller passes the manifest path.
    using System;
    using System.IO;
    using ShanghaiWindy.Editor;
    
    public static class CiModBuild
    {
        public static void Run()
        {
            var args = Environment.GetCommandLineArgs();
            var index = Array.IndexOf(args, "-modManifest");
            if (index < 0 || index + 1 >= args.Length)
            {
                throw new ArgumentException("Supply -modManifest followed by the JSON path.");
            }
    
            Utility_BuildPipline.BuildPiplineManifest(Path.GetFullPath(args[index + 1]));
        }
    }
    

    3. Create a Pipeline and check the build

    1. Save the script below as CI/Build-Mod.ps1 in the Unity project. Win64 is Unity 2022.3's command-line switch value. The manifest still uses StandaloneWindows64. Unity Editor command-line arguments
    $ErrorActionPreference = 'Stop'
    $project = (Resolve-Path .).Path
    $manifest = Join-Path $project 'CI/ModBuild.json'
    $output = Join-Path $project 'Build/Ship/Windows'
    $log = Join-Path $project 'Build/UnityBuild.log'
    New-Item -ItemType Directory -Path $output -Force | Out-Null
    if (Get-ChildItem -LiteralPath $output -Filter '*.modpack' -File) {
        throw "Use a clean output directory before building: $output"
    }
    $arguments = @(
        '-batchmode', '-quit', '-projectPath', ('"' + $project + '"'),
        '-buildTarget', 'Win64', '-executeMethod', 'CiModBuild.Run',
        '-modManifest', ('"' + $manifest + '"'), '-logFile', ('"' + $log + '"')
    )
    $build = Start-Process -FilePath $env:UNITY_EXE -ArgumentList $arguments -Wait -PassThru -WindowStyle Hidden
    if ($build.ExitCode -ne 0) { throw "Unity exited with $($build.ExitCode). See $log" }
    if (-not (Get-ChildItem -LiteralPath $output -Filter '*.modpack' -File)) {
        throw "No .modpack in $output. Check the manifest's target platform and directory."
    }
    
    1. Create a Jenkins Pipeline and select Pipeline script from SCM. Save the following Jenkinsfile at the repository root. Replace windows-unity with the label on your Windows agent. The Checkout stage resets this job's dedicated build workspace before cloning so each build has a fresh output directory. If the Unity project is in a subdirectory, wrap the PowerShell build step in dir('path/to/project') and prefix the archive patterns with that path. Jenkinsfile guide · PowerShell step
    pipeline {
        agent { label 'windows-unity' }
        options { skipDefaultCheckout() }
        stages {
            stage('Checkout') {
                steps {
                    deleteDir()
                    checkout scm
                    bat 'git lfs pull'
                }
            }
            stage('Build mods') {
                steps {
                    powershell '& ./CI/Build-Mod.ps1'
                    archiveArtifacts artifacts: 'Build/Ship/Windows/*.modpack'
                }
            }
        }
        post {
            always {
                archiveArtifacts artifacts: 'Build/UnityBuild.log', allowEmptyArchive: true
            }
        }
    }
    
    1. Choose Build Now with a teaching mod. Open Build/UnityBuild.log from the artifacts and check the target, the names built, and the destination. Before distributing a successful build, create the matching .modpack.json using the manifest guide and keep it alongside the archive. Check each archive's GUID, version, and target.
    In this article
    Back to top Panzer War Document