Docker combined with Jenkins, gitlab implementation. Continuous integration practice of Netcore

Source: Internet
Author: User
Tags dotnet administrator password asp net docker run webhook

The goal of this paper is to implement ASP NET core-based practices

Operating Environment

    • Cent OS 7
    • VS Code
    • . NET Core
    • Cmder
    1. Run Docker, set up the Docker image Accelerator, or the internal download image will be slow. To learn how to get started with Docker, you can refer to Docker entry and combat
    2. Create a docker network that allows containers to access each other
sudo Docker network create-d Bridge docker-net  

-D parameter indicates the Docker network type

    1. Docker running Jenkins
sudo Docker Run      8080:808050000:50000     --name Jenkins    --network docker-Net     -v/var/docker/jenkins:/var/jenkins_home-D     --restart always Jenkins

The-p parameter represents a port mapping so that you can access the container through the port number on your local machine

-D container runs in the background

-V Container Data map

Enter http://localhost:8080 in the browser to initialize the administrator password for the first entry. Wait for Jenkins to run and install the recommended plugin.

Install the Jenkins plug-in, Manage Plugins, Available, Manage Jenkins, find Blue Ocean, GitLab Plugin and restart Jenkins after installation

    1. Docker Run Gitlab
$sudoDocker Run--Detach--publish10443:443--publish8098: the--publish10022: A     --name Gitlab--Restart always--network docker-Net--Envgitlab_omnibus_config="gitlab_rails[' gitlab_shell_ssh_port ']=10022;external_url ' http://{ip}:8098 '"     --volume/var/docker/gitlab/config:/etc/Gitlab--volume/var/docker/gitlab/logs:/var/log/Gitlab--volume/var/docker/gitlab/data:/var/opt/Gitlab Gitlab/gitlab-ce:latest

External_url needs to be changed to your own IP address.

Run

Ps

Can view to the running container, first boot Gitlab will have a long time, waiting for Gitlab container status is healthy, browser open http://localhost:8098/, reset password, log in with root account

    1. Docker Run Registry
8097:--restart=always----network docker--v  /var/docker/ docker-registry:/var/lib/Registry registry:2

Open the http://localhost:8097/v2/in the browser to see if it runs successfully.

    1. Create a project on-premises ASPNET core project, create Dockerfile
$ dotnet New WEBAPI-

Open Http://localhost:5000/api/values in browser to see if it runs successfully

Create Dockerfile

From Microsoft/aspnetcore:2.0As Baseworkdir/Appexpose theFrom Microsoft/aspnetcore-build:2.0As Buildworkdir/srccopy. RUN dotnet Restoreworkdir/Srcrun dotnet Build-C Release-o/Appfrom Build as Publishrun dotnet publish-C Release-o/Appfrom Base as Finalworkdir/appcopy--from=publish/app. entrypoint ["dotnet","CIDemo.dll"]

Creating mirrors

127.0. 0.1:8097/cidemo:1 .

Run the image you just created

5001:127.0. 0.1:8097/cidemo:1

Open the http://localhost:5001/api/values in the browser to see if it is working properly

Create Jenkinsfile

Pipeline {Agent any stages {stage ('Build') {steps {SH " "Docker Build-t Registry:8097/Cidemo:${build_number}. Docker Push registry:8097/Cidemo:${build_number}" "}} stage ('Run') {steps {SH " "          Echo "Stop runing Container"Docker Stop $ (DockerPS-q) DockerRM$ (DockerPS-q) Docker run-d-p5001: the--network Docker-net Registry:8097/Cidemo:${build_number}" "      }    }  }}

Jenkinsfile Use tutorial https://www.w3cschool.cn/jenkins/jenkins-qc8a28op.html

    1. Set Gitlab API Token, configure Jenkins Gitlab

In Gitlab Personal Center, Settings, Acess Tokens, create a token that scopes contains the API.

Configure Gitlab in Configure System, Manage Jenkins, Jenkins. Gitlab host URL and API token.

In the Open Blue Ocean of Jenkins, create a pipeline, select the Git repository, and create a project that we just created.

In the Gitlab project, set Webhook, Projects-Settings, integrations, add a webhook, Url adds a Jenkins project address created in the previous step, e.g. http:// Jenkins:8080/project/cidemo, Secret token does not fill, tick the push events, do not tick enable SSL verification.

    1. Push code into the remote repository to see if the Jenkins task will be triggered, and if successful you can see the execution status of each step of Jenkins.

End, thank you, have a study of net core can add me ZJL_JX

Docker combined with Jenkins, gitlab implementation. Continuous integration practice of Netcore

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: info-contact@alibabacloud.com 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.