You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu 16.04上配置Jenkins实现Qt项目自动构建与测试?

Hey there! Since you’ve already got experience setting up CI for VS projects on Windows with Jenkins, Git, and xUnit, you’re well-positioned to adapt that workflow for Qt on Ubuntu 16.04. Let’s break down exactly what you need to do, including essential plugins, configuration steps, and common pitfalls to avoid.

Essential Jenkins Plugins

You’ll need these plugins to streamline the Qt build and test pipeline:

  • Qt Plugin: The most critical one—it auto-configures Qt environment variables (like QTDIR and PATH) and detects your Qt installation, so you don’t have to manually set paths every time.
  • Git Plugin: You’re already familiar with this—use it to pull code from your GitHub repository.
  • xUnit Plugin: Parses test reports generated by Qt’s test framework (Qt Test), just like you used it for VS projects.
  • Shell Plugin: Lets you run shell commands on Ubuntu to execute build and test scripts (replacing MSBuild from your Windows setup).
  • Credentials Binding Plugin: Manages GitHub credentials if your repository is private, so Jenkins can securely access your code.
Step-by-Step Configuration

1. Set Up Qt on Ubuntu 16.04 First

Before touching Jenkins, make sure Ubuntu has a working Qt environment:

Ubuntu 16.04’s default apt repo has older Qt versions (like 5.5), so I recommend using the official Qt installer to grab a more recent LTS version (e.g., Qt 5.12.x—this is compatible with Ubuntu 16.04’s GCC 5.4 compiler).

  • Install the official Qt installer, and select these components:
    • Qt 5.12.x (your chosen version)
    • Desktop gcc 64-bit (for Ubuntu’s 64-bit architecture)
    • Optional: Qt Creator for local debugging
  • Install build dependencies via terminal:
    sudo apt install build-essential make gcc g++
    

2. Configure Qt in Jenkins Global Settings

  • Go to Manage Jenkins > Global Tool Configuration
  • Scroll to the Qt section, click Add Qt
    • Name it something descriptive (e.g., Qt 5.12.10)
    • If you used the official installer, select Run from local machine and enter the Qt installation path (usually /opt/Qt/5.12.10/gcc_64)
    • Alternatively, use Install automatically to let Jenkins download and set up Qt for you
  • Save the configuration

3. Create a Jenkins Freestyle Project

Let’s set up the actual pipeline for your Qt project:

Source Code Management

  • Select Git, paste your GitHub repository URL
  • Add credentials (if private) via the Add button next to the credentials dropdown
  • Specify the branch you want to build (e.g., */main)

Build Environment

  • Check Provide Qt environment and select the Qt version you configured earlier. This ensures Jenkins uses the correct Qt tools (qmake, etc.) during the build.

Build Step (Execute Shell)

Add an Execute shell step with this build script (adjust paths to match your project structure):

# Clean up previous build artifacts
rm -rf build
mkdir build && cd build

# Generate Makefile with qmake
qmake ../your_project.pro  # Replace with your actual .pro file path
# If your project uses a specific spec, add it: qmake ../your_project.pro -spec linux-g++-64

# Build the project (use -j with your CPU core count to speed up builds)
make -j$(nproc)

# Optional: Install the built executable to a target directory
make install

Test & Report Step

If your project uses Qt Test for unit tests:

  1. Add another Execute shell step to run tests and generate XML reports:
    cd build/tests  # Path to your compiled test executable
    ./your_test_executable -xml > test_results.xml
    
  2. Add a Publish xUnit test result report post-build action:
    • Click Add and select QtTest
    • Enter the path to your test report: build/tests/test_results.xml
    • Save the project configuration
Common Pitfalls to Watch For
  • Qt Version Compatibility: Qt 5.15+ may not work with Ubuntu 16.04’s GCC 5.4—stick to Qt 5.12.x for stability.
  • Environment Variable Issues: If you installed Qt manually, ensure the Jenkins user (default: jenkins) has access to the Qt bin directory. You can add it to the global PATH via Manage Jenkins > Configure System > Global properties > Environment variables.
  • Permission Errors: The Jenkins user needs read/write access to your project directory and Qt installation. Use sudo chown -R jenkins:jenkins /path/to/your/project or add the jenkins user to the sudo group if needed.
  • Missing Dependencies: If make fails, check your .pro file for required Qt modules (e.g., QT += widgets network) and make sure those components were installed with Qt.

内容的提问来源于stack exchange,提问作者zhiyong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:30:21