jenkinsci/blueocean
镜像作为容器运行:jenkinsci/blueocean
Docker image.jenkinsci/blueocean
镜像作为一个容器运行。/var/jenkins_home
目录映射到名为 jenkins-data
的目录。如果这个目录不存在,那么这个 docker run
命令会自动为你创建目录。$HOME
目录(通常是 /Users/<your-username>
目录)映射到容器中的 /home
目录。jenkinsci/blueocean
镜像作为一个容器运行。docker exec
命令通过终端/命令提示符访问 Jenkins/Blue Ocean Docker 容器,则可以添加一个选项,如 --name jenkins-tutorials
(使用docker run上面),这将使 Jenkins/Blue Ocean Docker 容器的名称为“jenkins-tutorials”。docker exec
命令访问 Jenkins/Blue Ocean Docker 容器(通过单独的终端/命令提示符窗口)docker run ...
命令的终端/命令提示符窗口中键入Ctrl-C
来停止 Jenkins/Blue Ocean Docker 容器。docker run ...
命令。jenkinsci/blueocean
Docker 镜像。http://localhost:8080
。Jenkinsfile
at the root of your localsimple-java-maven-app
Git repository.Jenkinsfile
:image
parameter (of the agent
section’s docker
parameter) downloads the maven:3-apline
Docker image (if it’s not already available on your machine) and runs this image as a separate container. This means that:args
parameter creates a reciprocal mapping between the /root/.m2
(i.e. Maven repository) directories in the short-lived Maven Docker container and that of your Docker host’s filesystem. Explaining the details behind this is beyond the scope of this tutorial. However, the main reason for doing this is to ensure that the artifacts necessary to build your Java application (which Maven downloads while your Pipeline is being executed) are retained in the Maven repository beyond the lifespan of the Maven container. This prevents Maven from having to download the same artifacts during successive runs of your Jenkins Pipeline, which you’ll be conducting later on. Be aware that unlike the Docker data volume you created for jenkins-data
above, the Docker host’s filesystem is effectively cleared out each time Docker is restarted. This means you’ll lose the downloaded Maven repository artifacts each time Docker restarts. | | | Defines a stage
(directive) called Build
that appears on the Jenkins UI. | | | This sh
step (of the steps
section) runs the Maven command to cleanly build your Java application (without running any tests). |Jenkinsfile
and commit it to your local simple-java-maven-app
Git repository. E.g. Within the simple-java-maven-app
directory, run the commands: git add .
then git commit -m "Add initial Jenkinsfile"
simple-java-maven-app
Git repository itself, Jenkins:Build
stage (defined in the Jenkinsfile
) on the Maven container. During this time, Maven downloads many artifacts necessary to build your Java application, which will ultimately be stored in Jenkins’s local Maven repository (in the Docker host’s filesystem).Jenkinsfile
is open.Build
stage of your Jenkinsfile
:stage
(directive) called Test
that appears on the Jenkins UI. | | | This sh
step (of the steps
section) executes the Maven command to run the unit test on your simple Java application. This command also generates a JUnit XML report, which is saved to the target/surefire-reports
directory (within the /var/jenkins_home/workspace/simple-java-maven-app
directory in the Jenkins container). | | | This junit
step (provided by the JUnit Plugin) archives the JUnit XML report (generated by the mvn test
command above) and exposes the results through the Jenkins interface. In Blue Ocean, the results are accessible through theTests page of a Pipeline run. The post
section’s always
condition that contains this junit
step ensures that the step is always executed at the completion of the Test
stage, regardless of the stage’s outcome. |Jenkinsfile
and commit it to your local simple-java-maven-app
Git repository. E.g. Within the simple-java-maven-app
directory, run the commands: git stage .
then git commit -m "Add 'Test' stage"
Jenkinsfile
is open.Test
stage of your Jenkinsfile
:Deliver
that appears on the Jenkins UI. | | | This sh
step (of the steps
section) runs the shell script deliver.sh
located in the jenkins/scripts
directory from the root of the simple-java-maven-app
repository. Explanations about what this script does are covered in thedeliver.sh
file itself. As a general principle, it’s a good idea to keep your Pipeline code (i.e. the Jenkinsfile
) as tidy as possible and place more complex build steps (particularly for stages consisting of 2 or more steps) into separate shell script files like the deliver.sh
file. This ultimately makes maintaining your Pipeline code easier, especially if your Pipeline gains more complexity. |Jenkinsfile
and commit it to your local simple-java-maven-app
Git repository. E.g. Within the simple-java-maven-app
directory, run the commands: git stage .
then git commit -m "Add 'Deliver' stage"