step:
1, open jenkins client, log;
2, click on the left menu bar [New task], enter the task name, click on free-style software project, and click OK;
3, write a description of the current task
git address 4, fill in the source code management project, login account, where the code branches
5, the trigger constructed without checking, checking the build environment below:
6, building
1) Construction of increasing step of selecting execution shell
Box, enter the command:
source / etc / profile // refresh the environment variable configuration
mvn clean package //打包
sh service corresponding to the path of the file .sh .sh .sls file name server Ip address
7, storage, application
8, to jenkins where the server configuration file .sh and .sls
- Note: The file name and file .sh file .sls needs and git on the same project name
.sls file
.sh file
#!/bin/sh source /etc/profile SHELLPATH="/data/shell/" SALTPATH="/app/salt/base/init/" JENKINS_FILE="/app/salt/base/jenkins/files/" WORKSPACE="/data/data/jenkins/.jenkins/workspace/" PRO_NAME=$1 REMOTE_IP=$2 TARGET=`ls ${WORKSPACE} | grep ${PRO_NAME} | grep -v '@tmp' | grep TEST` PACKAGE_NAME=`/usr/bin/ls ${WORKSPACE}${TARGET}/target/ | grep 'jar' | grep -v 'original'` /usr/bin/cp ${WORKSPACE}${TARGET}/target/${PACKAGE_NAME} ${JENKINS_FILE} /usr/bin/cp ${SHELLPATH}salt_template.sls ${SHELLPATH}${PRO_NAME}.sls /usr/bin/sed -i "s/PRO_NAME/${PRO_NAME}/g" ${SHELLPATH}${PRO_NAME}.sls /usr/bin/sed -i "s/PACKAGE_NAME/${PACKAGE_NAME}/g" ${SHELLPATH}${PRO_NAME}.sls /usr/bin/cp ${SHELLPATH}${PRO_NAME}.sls ${SALTPATH} /usr/bin/salt ${REMOTE_IP} cmd.run "pkill -f ${PRO_NAME}" /usr/bin/salt ${REMOTE_IP} state.sls init.${PRO_NAME} /usr/bin/salt ${REMOTE_IP} cmd.run "echo 'source /etc/profile && nohup java -jar ${PACKAGE_NAME} > /dev/null 2>&1 &' > /app/java/${PRO_NAME}.sh" /usr/bin/salt ${REMOTE_IP} cmd.run "cd /app/java && nohup /usr/bin/sh ${PRO_NAME}.sh > /dev/null 2>&1 &"