C++ - Qt Framework - Using Jenkins to generate an .EXE file

In this tutorial we are going to see how to download a project directly on GitHub, generate makefiles of this project, compile it and copy several dynamic-link libraries from a directory to another one.

And all that automatically!

Let's see this in this Jenkins setup for Qt on Windows with MinGW.

First of all

We'll use one of my project that I already put on GitHub in order to use it as an example:

You don't need to download it, Jenkins will do that for us.

My Jenkins is installed in:

  • C:\soft\jenkins

The project which be downloaded from GitHub will be installed (automatically) in:

  • C:\soft\jenkins\workspace

My Qt with version 5.8 is installed in:

  • C:\Qt

I'll use the MinGW compiler for this tutorial with the version 530_64, so if you use the Microsoft Visual C++ (MSVC), just change the paths to yours.

In your Windows Environment variables (System variables and not User variables), add the following line (you can change the version of your MinGW of course): 

  • C:\Qt\Tools\mingw530_64\bin

For MSVC there are 2 paths to add: 

  1. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64
  2. C:\Qt\5.8\msvc2017_64\bin

It's time now to set the Jenkins server.


We supposed that you already installed Jenkins, so let's continue.

From Jenkins: New Item > Enter a name (like test1) > Click Freestyle project > OK.

You are now in Configure parameters for this project.

You can see this in the URL that should be something like that: 

In the General tab, you can see the project name: test1

For the Source Code Management tab, select: Git

Then as Repository URL write: https://github.com/badprog/badprog-qt-moving-shape-1.git

In the build Triggers tab, check Build periodically and write as Schedule:

H/2 * * * *

This will launch the process every 2 minutes for ever.

For the Build Environment, check Delete workspace before build starts.

It will show us that the project will be deleted every 2 minutes if we stay in the workspace directory.

OK now let's see the Build tab, which is the most important there.

Click the Add build step drop down menu > Execute Windows batch command.

In the following code if you are using MSVC replace mingw53_64 with msvc2017_64 for example.

Then replace win32-g++ with win32-msvc.

So in the Command text area type the following code:

:: BadproG.com
:: =====================
:: Generating Makefile |
:: =====================

"C:/Qt/5.8/mingw53_32/bin/qmake.exe" C:/soft/jenkins/workspace/test1/badprog-qt-moving-shape-1/moving-shape-1.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"

:: ===========
:: Compiling |
:: ===========

"C:/Qt/Tools/mingw530_32/bin/mingw32-make.exe" -f C:/soft/jenkins/workspace/test1/Makefile.Debug

:: ======================================
:: Moving .dll to the project directory |
:: ======================================

copy "C:\Qt\5.8\mingw53_32\bin\Qt5Cored.dll"       C:\soft\jenkins\workspace\test1\debug\Qt5Cored.dll
copy "C:\Qt\5.8\mingw53_32\bin\Qt5Widgetsd.dll"    C:\soft\jenkins\workspace\test1\debug\Qt5Widgetsd.dll
copy "C:\Qt\5.8\mingw53_32\bin\Qt5Guid.dll"        C:\soft\jenkins\workspace\test1\debug\Qt5Guid.dll
copy "C:\Qt\5.8\mingw53_32\bin\libgcc_s_dw2-1.dll" C:\soft\jenkins\workspace\test1\debug\libgcc_s_dw2-1.dll
copy "C:\Qt\5.8\mingw53_32\bin\libstdc++-6.dll"    "C:\soft\jenkins\workspace\test1\debug\libstdc++-6.dll"

copy "C:\Qt\5.8\mingw53_32\bin\libwinpthread-1.dll"    "C:\soft\jenkins\workspace\test1\debug\libwinpthread-1.dll"

All these lines can be replaced by setting correctly your Windows System environment variables with the corresponding binaries.

But for our example I thought that letting the complete paths of each line was quite interesting to understand it better.

OK, once you've typing all these lines in the Command text area, you can save it.

Click Save.

OK, on your left, click Back to Dashboard in order to see the current job test1 in the list.

You can start it manually or wait until it starts by its own.

To launch it, click the icon on the right of the test1 job line (a clock with a green triangle).

The job should start.

You can now open your directory in order to see the project downloaded from GitHub:

  • C:\soft\jenkins\workspace\test1\debug

You should see about 15 files (if you see less than 15 files, just wait until you have them all).

Here we go, double click the moving-shape-1.exe file in order to launch the application project.

Note for Git with SSH

If your Git repository needs SSH access, you have to use the Credentials directly from the Source Code Management of the Configure link (of your Jenkins job).

So from your job > Configure > Source Code Management, just below your Git Repository URL click the Add push button in order to enter your job credentials as follows:

  • Domain: Global Credentials (unrestricted)
  • Kind: SSH Username with private key
  • Scope: Global (Jenkins, nodes, items, all child items, etc)
  • ID: Let it empty.
  • Description: Let it empty.
  • Username: Up to you it's just to be chosen in the list credentials list.
  • Private Key: copy paste the content of your id_rsa file directly in the textarea.
  • Passphrase: The passphrase you used to generate your key.

As your Jenkins is running in the System Local Account profile (not your User profile) it's necessary to add your id_rsa file in this profile as well.

So copy/paste your id_rsa file in the following directory: 

  • C:\Windows\System32\config\systemprofile\.ssh

Restart your Jenkins server if needed and you are done.


This Jenkins tutorial for Qt is just the beginning of Continous Integration.

Very pleasant and useful when you want to have an assistant in your compilation process.

Good job, once again you did it! cool

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.