A complete instance of asp.net core + docker + Jenkins for continuous integration

Time:2020-1-6

Preface

In order to avoid repeated build and release in projects with separate front and back development, we need to deploy a continuous release environment, while the current development environment servers are based on CentOS, so after each local release, they need to pack, upload and deploy, which is very cumbersome. Therefore, the relatively mature Jenkins is used as the continuous deployment environment.

The method is as follows:

1. Create a new asp.net core MVC application:

Docker support needs to be checked

2. Upload it to git:

3. Create Jenkins task

(1) Select “new task”, enter the task name, select “free style project”, and then click OK:

(2) Select “source control” and fill in our git address

Input H / 2 * * to set pull once every two minutes

(3) Build environment

Delete workspace before build start

Check abort the build if it’s stuck to set the timeout time of the build. If the time used by the build exceeds the set time, then the build is considered to be a failure. The timeout setting here is 10 minutes

(4) Add an execute shell script and fill in the following script

#!/bin/bash
#Get short version number

GITHASH=`git rev-parse --short HEAD`
echo ---------------Remove-Orphans------------------
docker-compose -f ./docker-compose.yml -f ./docker-compose.override.yml -p webapplication6 down --rmi local --remove-orphans
echo ------------------Config-----------------------
docker-compose -f ./docker-compose.ci.build.yml -p webapplication6 config
echo ------------------Build------------------------
docker-compose -f ./docker-compose.ci.build.yml -p webapplication6 up --build
echo ---------------Publishing...------------------
docker-compose -f "./docker-compose.yml" -f "./docker-compose.override.yml" -p webapplication6 up -d --build

echo ---------------Clear-Images...------------------
docker rmi $(docker images -f "dangling=true" -q)
echo ---------------Clear-Containers...------------------
docker rm webapplication6_ci-build_1

On April 24, 2018, the image and container cleaning commands are added, so the above script is different from the following figure, and the shell script above shall prevail

Save the application and return to the project interface. Click build now to deploy

We can view the console output:

Visit the URL (your IP: port) to try the effect after the construction is successful.

If you don’t know the port, you can use the commanddocker psSee

reference material:

//www.jb51.net/article/139553.htm

//www.jb51.net/article/139555.htm

summary

The above is the whole content of this article. I hope that the content of this article has a certain reference learning value for everyone’s study or work. If you have any questions, you can leave a message and exchange. Thank you for your support for developepaar.