Automate the release of Jenkins at specified times by shell+atd scheduled tasks

Source: Internet
Author: User
Tags curl tmp file

Our company is through the Git+jenkins+shell+docker to achieve automated update release.

Here I say how I use the SHELL+ATD service, at 21:00 in the evening to complete the lead account of a project on-line operation. Note that this on-line project and on-line time is not fixed! Note: This is different from Jenkins ' timing task, which is a one-time task and needs to be set manually.

The CTO stipulates that the website will be released after 21:00 every day, and the development informs me that the API project will be online 9 o'clock at the end of work. TM back to play LOL or something easy to forget (CTO said: I hope this kind of thing will not happen!! ), how?

So, I wrote a shell,at 21:00/ (script path/script name) to complete the online task automatically.

Shell script running principle: Through Curl access to the Web page, with the command to determine the information built, success and failure to send a build reminder to the phone and mailbox, midway failure will not perform the next step.

Our Jenkins release needs to build 2 tasks to complete: the first step, the second release, which runs a script that performs several tasks in turn. Don't say much nonsense, put on the script.


# ——————————————————————— The following items need to be modified manually before use ——————————————————————

#开发测试 Jenkins Links

Jenkins_path= "Http://IP: Port/job"

#新版本接口 Jenkins Links

#jenkins_path = "Http://IP/view/All/job"


#buildJob = "It_test" #测试项目

#buildJob = "Tmp_accompany-server"

#buildJob = "Tmp-accompany-server_1-deploy"

#buildJob = "Tmp-accompany-server_2-deploy"

#构建任务列表, the build is executed sequentially

#arr = ("Tmp_accompany-server" "Tmp-accompany-server_1-deploy" "Tmp-accompany-server_2-deploy")

Arr= ("It_test" "It_test")

# ——————————————————————— The above content needs to be modified manually before use ——————————————————————

# —————————————————————————— Define the outgoing mail function —————————————————————————————————

Email () {

/sendemail/sendemail-f [email protected]-t [email protected]-t [email protected]-s "Build INFO"-O Message-content-type=html-o Message-charset=utf8-xu [email protected]-XP Quhu.hill.4-m $


# —————————————————————————— Define the Jenkins build function —————————————————————————————

Build () {


If [-Z $];then

echo "ERROR, no build link passed in! "

Exit 1


#把这个项目的页面信息存到build the. tmp file

Curl-s-o build.tmp ${1}


lastbuild=$ (grep-oe "Last Build \ (\#[0-9]*" Build.tmp |grep-oe [0-9]*]




Curl-u Admin:quhuhaohushi-s-D build-d delay=0sec ${1}build?delay=0sec

echo "Buliding ${buildjob} #${newbuild} Url:${1}"

Echo-n "Building ..."

Sleep 5

#访问最新构建结果信息放到build the. tmp2 file

#http://ip:port/job/test/buildhistory/ajax--header n:${num} num storage wants to see the build result information for a specific time

The result of the #下面为查看最新构建 (the build that was just triggered).

Curl-o build.tmp2-s--header N:${newbuild} ${1}buildhistory/ajax

#判断结果文件中是否包含 in Progress (queued) |pending (in the build), yes, every three seconds to get the results back to judgment.

While Grep-qe "in Progress|pending" BUILD.TMP2;


Echo-n "."

Sleep 3

Curl-o build.tmp2-s--header N:${newbuild} ${1}buildhistory/ajax




If Grep-qe "Success" BUILD.TMP2; then

echo "Build Success"

Email "Build success! ${buildjob} "


Elif grep-qe "Unstable" BUILD.TMP2;

echo "Build Success, but is a Unstable build"

Email "Build Success, but was a Unstable build"

Exit 1

#包含 <span style= "font-family:arial, Helvetica, Sans-serif;" >failed or </span><span style= "font-family:arial, Helvetica, Sans-serif;" >aborted words for build failure </span>

Elif Grep-qe "failed| Aborted "BUILD.TMP2;

echo "Build Fail"

echo "#Open Link: ${1}${newbuild}/console See details"

RM-RF build.tmp*

Email "Build fail! $buildJob "

Exit 1



RM-RF build.tmp*



# —————————————————————————— The end of the Jenkins build function ——————————————————————————————

# —————————————————————————— start to perform the build task —————————————————————————————————

For Buildjob in ${arr[@]};




Echo $jobPage

Build $jobPage


This article is from the "Spare Heart" blog, please be sure to keep this source

Automate the release of Jenkins at specified times by shell+atd scheduled tasks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.