Operations 9 min read

Using Jenkins to Build and Display WeChat Mini Program QR Codes

This guide explains how to configure Jenkins with the WeChat Mini Program Builder plugin, create a pipeline that builds the mini‑program, generates a QR code, and displays the latest QR image on the Jenkins dashboard for quick testing, including full pipeline and code examples.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Using Jenkins to Build and Display WeChat Mini Program QR Codes

During testing of WeChat mini‑programs, developers often face delays because bugs are fixed intermittently; this article shows how to use Jenkins to automatically build the mini‑program, generate its QR code, and display the latest QR image on Jenkins for easy scanning.

Setup steps: install the Jenkins Plugin for WeChat Mini Program Builder , create a new Jenkins Pipeline (or enable the plugin in an existing one), configure build steps for the mini‑program, and run a test build.

Detailed procedure:

Install the plugin via Manage Jenkins → Manage Plugins → Available and search for the WeChat Mini Program Builder.

Create a new Pipeline item, give it a name, enable pipeline features, enable SCM polling, and provide the Git URL.

Configure the plugin under Configure System → Global Tools Configuration , entering the App ID and Secret Key.

Add build steps such as wechatmp init and wechatmp build to the pipeline.

Trigger the build with Build Now , check the console output for errors, and test the resulting mini‑program in the WeChat developer tools.

Example Jenkins Pipeline (Declarative):

pipeline {
    agent any
    parameters {
        string(name: 'APP_ID', defaultValue: '', description: 'Your Wechat Mini Program APP ID')
        string(name: 'SECRET_KEY', defaultValue: '', description: 'Your Wechat Mini Program Secret Key')
    }
    stages {
        stage('Checkout') {
            steps { checkout scm }
        }
        stage('Build') {
            steps {
                echo 'Building your WeChat Mini Program...'
                script {
                    node {
                        sh """
                        npm install
                        npm run build
                        """
                    }
                }
            }
        }
        stage('Deploy') {
            steps {
                script {
                    node {
                        def buildDir = '/var/tmp/build'
                        dir(buildDir) {
                            // Move build output
                            sh 'mv dist/* .'
                            // Initialize and build with the plugin
                            wechatmp init ${params.APP_ID} ${params.SECRET_KEY}
                            wechatmp build
                        }
                    }
                }
            }
        }
    }
}

The pipeline checks out code, runs npm install and npm run build , moves the build output, initializes the mini‑program with the provided credentials, and finally builds it.

Displaying the QR code on Jenkins: install a QR Code Generator plugin, generate a QR image, embed it in a JUnit XML report, and use a WeChat mini‑program plugin to parse the XML and show the QR code. The QR code must be generated before sending it to the mini‑program.

Java example for QR code generation:

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

public class QrCodeGenerator {
    public static void main(String[] args) throws WriterException, IOException {
        String content = "Hello, World!";
        int width = 300; // QR code width
        int height = 300; // QR code height
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        Map
hints = new HashMap<>();
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
        Path file = Paths.get("/tmp/test.png");
        MatrixToImageWriter.writeToFile(bitMatrix, "PNG", file.toFile());
        System.out.println(file.toString());
    }
}

This code converts a string into a QR code PNG file that can be archived as a build artifact and later displayed in the mini‑program.

Python version (compatible with the Jenkins pipeline):

from PIL import Image
from pyqrcode import create as qrcode

def generate_qrcode(image_path):
    qr_code_data = 'Hello, World!'
    qr_code_image = qrcode.create(qr_code_data)
    qr_code_image.save(image_path)

def build_wechat_app():
    APP_ID = input("Enter your APP_ID:")
    SECRET_KEY = input("Enter your SECRET_KEY:")
    # Clean previous build
    subprocess.call(['rm', '-rf', 'dist'])
    # Build the mini‑program
    subprocess.call(['npm', 'run', 'build'])
    # Move build output
    subprocess.call(['mv', 'dist', '/var/tmp/build'])
    # Initialize the mini‑program
    subprocess.call(['wechatmp', 'init', APP_ID, SECRET_KEY])
    # Generate QR code
    generate_qrcode('/tmp/qrcode.png')

if __name__ == '__main__':
    build_wechat_app()

The Python script performs the same steps: it builds the mini‑program, initializes it with credentials, and generates a QR code image that can be uploaded as part of the Jenkins build results.

CI/CDautomationWeChat Mini ProgramQR codepipelineJenkins
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.