This article has participated in the Denver Nuggets Creators Camp 3 “More Productive writing” track, see details: Digg project | creators Camp 3 ongoing, “write” personal impact.

Jenkins profile

Jenkins automatic deployment can solve the integration, testing, deployment and other repetitive work, the efficiency of tool integration is obviously higher than manual operation; And continuous integration can earlier to get code changes, thus earlier entered the testing phase, found the problem earlier, so the cost will be a significant reduction in: to solve the problem from continuous integration shortens the development, integration, testing, deployment, each link of the time, thus shortening for the waiting time in the middle; Continuous integration also means continuous development, integration, testing, and deployment.

Jenkins is an open source continuous integration tool written in Java. Official website: Jenkins.io

Jenkins can monitor problems during continuous integration in real time, provide detailed log files and reminders, and graphically show the trend and stability of project construction.

1 Script Content

#! /bin/bash cat /dev/null > nohup.out NUM=`netstat -tunlp | grep 8000 | wc -l` if [ ${NUM} -eq 0 ]; then echo "Service not start.starting......." Nohup python36 /data/webPage/manage.py runserver 0.0.0.0:8000 & else echo "Service already run on 0.0.0.0:8000Copy the code

The script content is very simple, is to detect whether port 8000 is listening, if not listening to try to start the service, if listening to exit normally.

2 questions

After Jenkins built the pull code, he pushed the code to the business machine through the Publish Vver SSH plug-in, and when executing the script, the nohup command in the script could not exit normally, resulting in the foreground of the construction task being stuck. As shown in figure:

3 screening

After query, it is found that:

Since you are executing a script from a non-TTY environment; The Jenkins is not able to get the exit properly, out of your script.What you want is to exit immediately, after script execution! Don’t want to wait for the entire timeout to happen and then disconnect improperly!

Meaning:

Execute scripts from a non-TTY environment; Jenkins can’t exit your script properly

4 to solve

Use Exec in PTY

The build is done, butThe service did not startThe possible reason is because of the executionopenapi startThe pTY (pseudo terminal) is disconnected immediately after startup.

The solution is to add nohup so that the steps run in the background, so that even if the pseudo-terminal is disconnected, the project can still be started and completed.