I. New Jenkins Project

There’s nothing to say about this step, just create a free style

2. Install plug-ins

Because I pulled the code from Git, the Git plug-in had to install the SSH publishing plug-in: Publish Over SSH

Three, configuration,

1. Configure the SSH server

Enter Configure System to set the SSH password

Example Set SSH information

You can click Test to see if it is correct

2. Prepare the sh file on the SSH server

Because Golang’s programs, unlike Java, can be replaced running, prepare two SH files. Put it in the directory you want to run it in.

One is stop.sh and start_jenkins.sh

And give them permission chmod 777 stop.sh start_jenkins.sh

stop.sh

#! /bin/sh # PORT=8201

DATE=`date '+%Y%m%d'`
for port in ${PORT}
do
    pid=`netstat -anltp | grep $port | awk '{print $7}' | awk -F"/" '{ print $1 }' | head -1`
    if  [ ! -n "$pid" ] ;then
        continue
    else
        kill 9 - $pid

    fi
done

echo "Successfully closed"

exit 0

Copy the code

“Exit 0” on the last line must be added otherwise Jenkins will not get the message that you are successful

start_jenkins.sh

#! / bin/sh # port nohup. / report. Pubcom. Maque. The cloud > >. / logs/nohup`date +%Y-%m-%d`.out 2> &1 &

exit 0
Copy the code

3. Jenkins project configuration

Source configuration

On the build node, configure stop.sh

Configure your Remote directory

Perform the go build

Submit the file to the server and execute start_jenkins.sh

Four, pay attention

Because my golang called the Oracle library, calling start.sh kept getting an error

64-bit Oracle Client library cannot be loaded: “libclntsh.so: cannot open shared object file

But it is good to boot directly from SSH. Checked the data, need to add configuration on the server

vim /etc/ld.so.conf;
Copy the code

# # at the end of the add/maque/tools/instantclient_18_5 according to you install oracle version driver path

# save run

ldconfig
Copy the code