Jenkins Android Package (Mac)
First, install Tomcat
A. Download Tomcat
http://tomcat.apache.org/
When the download is complete, unzip to:
/Users/xiaxveliang/Library/
Copy the code
B. Start Tomcat:
sudo sh startup.sh
Copy the code
C, validation,
2. Install Jenkins
A, Download Jenkins.war
https://jenkins.io/index.html
Once the download is complete, place it in the following path:
/Users/xiaxveliang/Library/ApacheTomcat/webapps
Copy the code
B, open
http://localhost:8080/jenkins
C. InitialAdminPassword cannot be found
Can’t find
/var/root/.jenkins/secrets/initialAdminPassword
Copy the code
MAC cannot open folder XXX because you do not have permission to view its contents
D. Modify Jenkins Job catalog
// The modified job directory
/Users/xiaxveliang/a_Work/Jenkins/${JOB_NAME}
Copy the code
E. Add Git credentials
F. Discard principle
G. Choose to build branches
* /$BRANCH
Copy the code
Note: Download the Persistent Parameter plugin to remember the Parameter selection for the last successful build
H. Timing construction
// Timed build: Weekdays (Monday to Friday)9 to 18 every 2 hours to build
H 9-18/2 * *From 1 to 5
// Polling: checks every 5 minutes for code updates
H/5 * * * *
Copy the code
I, build
build apk
A shell script build
# build
/ Applications/Android \ Studio app/Contents/gradle/gradle - 4.10.1 / bin/gradle clean assembleRelease
Copy the code
Shell script rename apk
# rename
mv $WORKSPACE/build/outputs/apk/test-release.apk $WORKSPACE/build/outputs/apk/$JOB_NAME-$BUILD_NUMBER-$BRANCH.apk
Copy the code
J. Filing (done)
# Archive file
* * /$JOB_NAME-$BUILD_NUMBER-$BRANCH.apk
Copy the code
At this point, it’s safe to say that the Jenkins Android package is complete. But we still have some other details to work on, such as generating qr codes and sending emails
Generate an Html file pointing to job_name-build_number-branch. apk
Shell Script Screenshot
A shell script
#create html
cd $WORKSPACE/build/outputs/apk
rm -rf $JOB_NAME.html
touch $JOB_NAME.html
cat << EOF > $JOB_NAME.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width"/>
<title>$JOB_NAME</title>
</head>
<body>
<h3><a href="Http://10.236.148.225:8080/jenkins/job/$JOB_NAME/$BUILD_NUMBER/artifact/build/outputs/apk/$JOB_NAME-$BUILD_NUMBER-$BRAN CH.apk">$JOB_NAME-$BUILD_NUMBER-$BRANCH</a>
</h3>
</body>
</html>
EOF
#copy html to tomcat folder
Copy the code
Archive JOB_NAME. HTML
* * /$JOB_NAME-$BUILD_NUMBER-$BRANCH.apk,**/$JOB_NAME.html
Copy the code
L, generate a qr code — > point to JOB_NAME
Download the QRcode. Jar
QRcode. Download the jar
Shell Script Screenshot
A shell script
# java -jar xxx/QRcode.jar url=xxx/test.apk image=qrcode.png save=xxx/xxx/
java- jar/Users/xiaxveliang/Library/Tomcat/webapps/QRCode. Jar url = HTTP: / / http://10.236.148.225:8080/jenkins/job/$JOB_NAME/$BUILD_NUMBER/artifact/build/outputs/apk/$JOB_NAME.html image=qrcode.png save=$WORKSPACE/build/outputs/apk/
Copy the code
Archive qrcode. PNG
* * /$JOB_NAME-$BUILD_NUMBER-$BRANCH.apk,**/$JOB_NAME.html,**/qrcode.png
Copy the code
M. Mail sending
Jenkins/ Systems Administration/System Settings
job_name/configure
The mail template
<html>
<head>
<meta charset="UTF-8">
<title>${ENV, var="JOB_DESCRIPTION"}</title>
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"
offset="0" >
<h3>Please do not reply to Jenkins' automated email below!</h3>
<div>
<table width="95%" cellpadding="0" cellspacing="0" border="1"
style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
<tr>
<th><br />
<h2>Build information</h2>
</th>
</tr>
<tr>
<td>
<ul>
<li>Project name: $JOB_NAME-$BUILD_NUMBER-$BRANCH</li><br />
<li>Branches: ${BRANCH}</a></li><br />
<li>${BUILD_NUMBER}</li><br />
<li><font size="3" color="black"><b><a href="Http://10.236.148.225:8080/jenkins/job/${JOB_NAME} /">Click to see details of the build</b></a></li><br />
<li>$BRANCH:<img src="http://10.236.148.225:8080/jenkins/job/$JOB_NAME/$BUILD_NUMBER/artifact/build/outputs/apk/qrcode.png"/></li><br />
<li><a href="Http://10.236.148.225:8080/jenkins/job/$JOB_NAME/$BUILD_NUMBER/artifact/build/outputs/apk/$JOB_NAME-$BUILD_NUMBER-$BRAN CH.apk">Android client download address</a> </li><br />
<li #right-panel .data { line-height: 19px; white-space: initial; } >git log: ${CHANGES_SINCE_LAST_SUCCESS}</li><br />
</ul>
</td>
</tr>
</table>
</div>
</body>
</html>
Copy the code
N. Switch to the Test /online environment
# test or online
# file
FILE_DIR=$WORKSPACE/src/com/test/constants/NetConstants.java
# code test or online
Test_Str="public static boolean TEST = true"
Online_Str="public static boolean TEST = false"
# test
# sed 's/123/456/g' replace 123 to 456
if [ $ENV_TEST = "true" ];then
`sed -i.bak "s/$Online_Str/$Test_Str/g" $FILE_DIR`
elif [ $ENV_TEST = "false" ];then
`sed -i.bak "s/$Test_Str/$Online_Str/g" $FILE_DIR`
fi
# build
/ Applications/Android \ Studio app/Contents/gradle/gradle - 4.10.1 / bin/gradle clean assembleRelease
Copy the code
Note: For details about how to use the sed command, see the different usage modes of the sed command on MAC and Linux