Wechat development tool is an important tool for us to develop wechat small program, providing preview, upload code function, but the upload code in the process of collaboration is very painful, at the same time, there can only be a preview version, the preview version is bound with a developer. Imagine that there are five developers out there, and one of them is going to be responsible for the launch.

In addition, the release of small programs is heavily dependent on the developer and his or her computer, and in the event of an emergency there may be no one to release them.

We all know that Jenkins is used for automated build, which is used in many projects, so we finally developed the Mimi-deploy script plug-in to work with Jenkins.

Of course, Mini-deploy is not limited to this, it can also be executed in any Node.js environment and used with your program, which is as imaginative and efficient as you can be.

We introduced the use of mini-deploy in the same way we used it in Jenkins, so let’s get started.

1. Prepare requirements

Requirements are as follows:

  • Running on thewindowsorMacSystem computer
  • jenkinsRun on the computer
  • Wechat development tools are installed on the computer
  • A wechat signal

2. How do I configure the configuration

2.1 Creating a Task

Assuming we’ve run Jenkins, click “New Task” to start filling in the task information, enter the task name and select “Build a Free-style software project”.

If you need to create more than one task, you can finally “copy” the function.

2.2 Configuration Task

2.2.1 Source code management

To configure the project code in “Source Code Management”, take Git as an example, you need to configure two parameters:

  • Repositories address and authentication mode
  • Branches to build, we fill in$branchIs specified as a custom build parameter

2.2.2 Parametric construction process

Select “Parameterized build process” in “General”, then click “Add Parameters”, select Git Parameter from the candidate list, and configure the following two items:

  • Name: Specifies the variable name that can be accessed. For example, if configured as branch, the value can be obtained from $branch
  • Parameter Type: Select Branch. Other options can be configured as required

This gives $Branch, which was configured earlier in “Source Management”, access to all branches of the repository.

You also need to add two text parameters: upload_version and upload_DESC (the version number and description used to publish the applette).

And an option argument: build_type, which specifies the target environment in which the applets are packaged. Candidate data can be entered one line at a time.

2.2.3 Adding the Build Execution Shell

In “Build” click the “Add Build Step” button and select “Execute shell” from the candidate list.

This step is the most critical, we’ll call mini-deploy to release the applittle, first Posting the shell script I’m using:

#! /bin/bash
echo -------------------------------------------------------
echoCode branch:${GIT_BRANCH}
echo -------------------------------------------------------
# Preparation

# Accelerate package installation and Node-sass
# Nod-sass = nod-sass = nod-sass
yarn config set registry https://registry.npm.taobao.org
yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass

# Install dependencies
yarn install 

Delete dist and perform packaging
if [ "$build_type"= ="dev" ]
  then
  rm -rf dist && yarn run build
else
  rm -rf dist && yarn run $build_type
fi

if [ "$build_type"= ="prod"] | | ["$build_type"= ="build" ]
  then
    mini-deploy --mode=upload --ver=$upload_version --desc="$upload_desc" --login.format=image --login.qr='login.png' --no-resume

    let "result |= $?"

    if [ "$result"= ="0" ]
      then
        Send notifications to nail groups
        yarn run notify
      fi
else
  rm -rf ./preview.png
  rm -rf ./login.png
  mini-deploy --mode=preview --login.format=image --login.qr='login.png' --no-resume
  
  let "result |= $?"
      
  if [ "$result"= ="2" ]
    then
    	echo "need login"
  fi
fi
Copy the code

There are two ways to use Mini-deploy: development preview and upload code. Here we need to explain the use of parameters in it.

After users scan the code to log in to the wechat development tool, after a period of time may be invalid login, this time to call upload and preview is invalid, we have to scan the code to log in again. Format and login.qr indicate the storage mode and file name of the specified qr codes. Currently, the login codes include terminal (command-line output), base64, and image.

Because the execution result cannot be obtained in real time in Jenkins, we need to configure no-resume to prevent mini=deploy from completing the task directly after obtaining the login QR code from the resume task.

In addition, we configure the format of the QR code as image and output it to login. PNG in the project workspace. Then, with other configurations, we can see the login QR code in Jenkins.

# upload code
mini-deploy --mode=upload --ver=$upload_version --desc="$upload_desc" --login.format=image --login.qr='login.png' --no-resume

# preview
mini-deploy --mode=preview --login.format=image --login.qr='login.png' --no-resume
Copy the code

2.2.4 TWO-DIMENSIONAL code result display

In the “Post-build Operations” section, click “Add Post-build Steps” and select Set Build Description:

  • Regular expression : \[mini-deploy\] (.*)
  • Description : \ 1

The configuration here is to display a reminder that the user needs to log in, as well as the development code and the success of the upload.

// The log contains the following record: [mini-deploy] Enter Build details scan the development code to enter the small program'// After a successful match,' \1 'represents the following information to enter the Build details scan the development code to enter the appletCopy the code

3. Running result

The final result of our operation is as follows:

  • Development preview can be re-built by scanning qr code to enter the history
  • The login qr code is displayed when you need to log in
  • If the code is successfully uploaded, only a message is displayed

This article is published on the author’s blog: wechat Mini Program and Jenkins had to say two or three things