When UniApp needs to upload the new version of small program, it needs to go to the corresponding platform (wechat/byte/Alipay /..) every time. It’s ok if you don’t do it frequently, but if you update it often, you feel stupid. So we wanted to make it easy and fun with Jenkins & Scripts, just run a command
The initial idea
Implementation steps
I’m using Aliyun’s server here
The deployment of Jenkins
Install the JDK before doing so, which will not be covered here
-
Download the dependent
Sudo/etc/wget – O. Yum repos. D/Jenkins. Repo PKG. Jenkins. IO/redhat – stab…
-
Import the secret key
Sudo RPM – import PKG. Jenkins. IO/redhat – stab…
-
The installation
# yum install Jenkins # yum install Jenkins
If you need to change the port and other configurations, do so in this file. The default is port 8080
vi /etc/sysconfig/jenkins
Copy the code
Start, stop, restart commands
service jenkins start
service jenkins stop
service jenkins restart
Copy the code
The first run need password, the password in/var/lib/Jenkins/secrets/initialAdminPassword file
After that, the Jenkins environment will be initialized, you can choose the recommended configuration, and some plug-ins will be installed automatically
Configuration making SSH
You need to configure global authentication first because the pull code requires it. Using the Github hosting project as an example, SSH is recommended
Ps :accessToken can also be encrypted free, but accessToken of each project is different. SSH is more common and can be configured once
How to Configure SSH
The following error may occur after the configuration is complete
ssh:connect to host github.com port 22: Connection timed out
Copy the code
Solution: Modify the config file in ~/. SSH /
Ssh.github.com IdentityFile ~/.ssh/id_rsaCopy the code
At this point, it may be possible to clone the code on the server, but running Jenkins still generates a port22 error
Since the Jenkins directory also has.ssh, it may overwrite the.ssh configuration in the root directory
Solution:
Copy the contents of the system's.ssh directory to /var/lib/jenkin/.ssh/Copy the code
Add Jenkins’ credentials
Manage Credentials
Then add credentials of type SSH
Copy the contents of.ssh/id_rsa here and save
Configuration webHook
WebHook: Notify Jenkins of push or other operations in the source repository and perform build tasks
Refer to the article
Configure the nailing robot
Notify yourself of build results
Why not use QQ/wechat robot: scan code login, no login free mode
Refer to the article
Task allocation
Create a task
Choose free style
jenkins robot
Here you can customize the content in Markdown format and also add images
Configuration of the warehouse
build
Write a script
Here refer to official documents of wechat, Alipay and Byte
WeChat applet CI tools: developers.weixin.qq.com/miniprogram…
Byte applet CI tools: microapp.bytedance.com/docs/zh-CN/…
Alipay applet CI tools: opendocs.alipay.com/mini/02q17j
Both provide upload code function
You need to install the above command line tools on Jenkins’ server in advance
Refer to the script
# jenkinsbuild. sh VERSION=$1 UPLOAD_MSG=$2 TAG_NAME=$tag DEV_URL="abct.123.com" if [ -z "$TAG_NAME" ]; then #statements TAG_NAME="dev" fi if [ -z "$VERSION" ]; Then VERSION=" default VERSION 1.0" fi if [-z "$UPLOAD_MSG"]; $TAG_NAME $VERSION $UPLOAD_MSG" $TAG_NAME $VERSION $UPLOAD_MSG "master" ]; Sed -i "" "s/$DEV_URL/$PRODUCT_URL/" SRC /utils/util.js else git checkout Sed -i "" "s/$PRODUCT_URL/$DEV_URL/" SRC /utils/util.js fi echo" Waiting to install NPM dependencies..." NPM install echo "=== NPM install echo "... Waiting to compile various platform applets..." NPM run build:mp-weixin NPM run build:mp-toutiao NPM run build:mp-alipay echo "=== "# echo" Waiting for wechat applets to upload..." Miniprogram-ci upload --pp./dist/build/mp-weixin -- PKP./wxupload.private.key -- appID wx888888888888 -- UV 1.0.0-r 1 - enable - es6 true echo "= = = WeChat small program to upload finished = = =" echo "... Waiting for byte applets to upload..." tma login-e [email protected] passwdxxxxx echo "... Byte login completed, waiting for upload..." Tma upload -v 1.0.0 -c "test upload script 11" -path. /dist/build/mp-toutiao # bytes echo "=== bytes Echo" Waiting for alipay small program to upload..." minidev config set alipay.authentication.privateKey "-----BEGIN PRIVATE KEY----- MIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxs= -----END PRIVATE KEY-----" minidev config set alipay.authentication.toolId 8c15xxxxxxxxxxxxxxxxxxxx #export MINIDEV_RUNTIME_CONFIG={"alipay.authentication":{"privateKey": "xxxxxxxxxx", "toolId": Minidev upload -a 2021003108610029 -v 1.0.0-p./dist/build/ mp-Alipay echo "=== "#TODO Output Experience qr code associated pin notification configurationCopy the code