Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Jenkins continuous Integration-Parametric Construction

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. String Parameter

Because the SVN path specified during each build is different, if you do not use parameterized build, you need to modify the SVN path in the configuration every time, which is not only unsafe but also prone to errors.

Set the SVN address to the string parameter (string parameter), and the user will be prompted to enter the parameter value (that is, the SVN address) when the build starts.

Reference parameters in SVN

In addition, if you need to automatically pull SVN tag or git branch can use "List Subversion tags (and more)" and "Git Parameter Plug-In" these two plug-ins, will automatically fill in the SVN/git address under the subdirectory, interested friends can study for themselves.

When the build is executed, the page will pop up and wait for the user to enter parameter values to complete the build.

II. Choice

Since the state detection of tomcat has not been parameterized before, each module needs a corresponding job for detection, which will eventually lead to a large number of job created, which will not only increase the workload, but also prone to errors.

The following will merge it into a single job of Tomcat_check by parameterizing it.

Before merging:

After the merger:

Check the configuration parameterization construction process (select "Chice" and define the value of the parameter named Module,Choices and fill in the required options according to your own situation)

Build process (executes the check.sh script and references the parameter Module)

Trigger mail steps (will be described in detail in the mail plug-in)

The script for testing tomcat is attached below (for reference only)

Tomcat_check detection script

Define a check function to detect whether tomcat starts a normal functions

# define the number of retries after failure ATTEMPTS=12FAILED=0# definition will output the log of the version number (which can be used to send mail) the log generated when file=$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/check#jenkins is built Used to append log output to jenkins console log=$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/logcheck () {echo\ `date` > $file # execute while [$#! = 0] do IP= `echo $1 when calling check function with parameters | awk-F "/"'{print $3}'| awk-F':'{print $1} '`ver= `curl-skf-m 1 $1 | grep-I "v" | head -1 | dos2unix` curl-skf-m 1 $1 > / dev/null # when the curl detection URL returns normal, record the IP and version number to $file and output "$1 is OK" (shift is used to move one bit to the left) if [$?-eq 0] to the jenkins console Then echo\ $IP\ + $ver > > $file echo $1 is OK! > > $log FAILED=0 shift continue else # when curl detects that URL returns an exception, wait 10 seconds and then retry FAILED=$ (($FAILED + 1)) TIMES=$ (($ATTEMPTS-$FAILED + 1)) echo "Waiting for check the web-$1 Retrying in 10 seconds for $TIMES times... "> $log sleep 10 if [$ATTEMPTS-gt $FAILED] Then continue else echo "Failed to check the web-$1" > $log fi # if you still fail after retrying for a specified number of times, record the version number as ERROR and set the font to red echo\ $IP\ +\ Error\ > $file FAILED=0 shift continue fi done}

Call the check function check.sh defined above through a script

# introduce parameters to specify the module to be detected (that is, Module in parametric construction) Module=$1# refers to the check function in functions. / data/ztjy/functionsargs= `cat / data/ztjy/$Module/ url`check $args# extract the new version number (relative to other versions) Maxver= `awk-F "+" {print $3}'$file | grep-I v | sort | tail-1`` # extract the old version number Minver= `awk-F "+" {print $3}'$file | grep-I v | sort | head-1` # if the new version number is changed to orange sed-I "s/$Maxver/ $Maxver/g" $file # if it is an old version number, the font of this version will be displayed as green sed-I "s/$Minver/ $Minver/g" $file

Perform a parametric build

The email notification will be triggered automatically after the detection is visible above. The email content is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report