Jenkins结合Git子模块构建新手技术咨询
Hey there! Let’s break down how to tackle your Jenkins build challenges with this submodule-heavy Visual Basic project setup. I’ve worked through similar repo structures before, so here’s what I recommend:
1. Ensure Jenkins Pulls Parent Repo + Submodules Correctly
Submodules are often the culprit in build failures because Jenkins doesn’t automatically fetch them by default. Here’s how to fix that:
- In your Jenkins project’s Source Code Management section (under Git), add your parent
Project_Folderrepo URL. - Scroll down to Additional Behaviours and click Add. Choose Recursively update submodules—this tells Jenkins to pull all nested submodules (FolderA.1, FolderB.1, FolderB.2) alongside the parent repo.
- If your submodules are private repos, add another behaviour: Specify credentials for submodules. Pick the appropriate Jenkins credentials (username/password or SSH key) that have access to those submodule repos.
2. Configure Visual Basic Builds with MSBuild
Since you’re working with VB projects, MSBuild is your go-to tool. Here’s how to structure your build steps:
- First, make sure the MSBuild Plugin is installed in Jenkins, and you’ve configured the path to your MSBuild executable (usually
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exefor VS 2022 Build Tools). - You can either build each submodule’s VB project individually, or use a solution file if you have one. For example, add a Windows Batch Command build step with:
:: Build FolderA.1 VB project msbuild "%WORKSPACE%\FolderA\FolderA.1\YourVBProject.vbproj" /p:Configuration=Release /p:Platform=x86 :: Build FolderB's submodules msbuild "%WORKSPACE%\FolderB\FolderB.1\AnotherVBProject.vbproj" /p:Configuration=Release /p:Platform=x86 msbuild "%WORKSPACE%\FolderB\FolderB.2\ThirdVBProject.vbproj" /p:Configuration=Release /p:Platform=x86
- Pro tip: If your VB projects reference shared files from
FolderC, double-check that the project references use relative paths (e.g.,..\..\..\FolderC\SharedUtility.vb). This ensures the paths work correctly in Jenkins’ workspace, just like they do on your local machine.
Since FolderC holds shared assets across your submodules, you need to make sure these files are accessible during builds:
- Avoid hardcoding absolute paths in your VB projects—relative paths are the way to go here. If you’re having trouble with path resolution, you can add a pre-build step to copy
FolderCcontents to a directory each submodule expects, but relative paths are cleaner. - Add a quick check in your build script to verify
FolderCexists (just to catch any accidental repo issues):
if not exist "%WORKSPACE%\FolderC" ( echo ERROR: FolderC is missing from workspace! exit /b 1 )
4. Archive Build Artifacts & Clean Up
Once builds succeed, you’ll want to save the output files:
- Add an Archive the artifacts post-build action. Use a path like
**/bin/Release/**to capture all executable files, DLLs, and other output from your VB submodules. - If you want to clean the workspace before each build, enable Delete workspace before build starts—but don’t worry, the submodule pull step will re-fetch everything you need.
内容的提问来源于stack exchange,提问作者Guilherme Ferreira
相关产品推荐
相关产品推荐

