CI/CD流程 命令列方式與Jenkins Blue Ocean方式
命令列模式
環境準備
- 克隆程式碼
git clone
- 啟動私有docker hub
docker run -d -p 5000:5000 -v /data/registry:/var/lib/registry --name registry --r
estart=always registry
- 製作建置環境
docker build -t localhost:5000/maven dockers/maven
dockers/maven/Dockerfile
FROM
## 安裝openjdk
## 安裝Maven
CMD ["mvn"]
整合、測試、驗證
- 進行自動化測試
docker-compose run --rm test
docker-compose.yaml
data:
image: alpine
volumes:
- ~/.m2:/root/.m2
command: "/bin/bash"
install:
image: localhost:5000/maven
volumes:
- ./:/app
volumes_from:
- data
working_dir: /app
command: 'mvn test'
server:
image: localhost:5000/maven
volumes:
- ./:/app
- ~/.m2:/root/.m2
working_dir: /app
ports:
- "8000:8000"
command: "mvn spring-boot:run"
- 啟動 alpha server
docker-compose up -d server
- 人員確認啟動狀況
- 關閉alpha server
docker-compose stop server
- 產出報表與封存
docker-compose run --rm package
部署
- 構建生產映象
不需要maven,把額外的都去掉,保留最乾淨的環境,Dockerfile一般放在根目錄下
make build-docker-prod-image
# Dockerfile
FROM java
COPY target/spring-boot-simple-data-rest-0.1.0.jar /app/
EXPOSE 8000
WORKDIR /app
CMD /bin/bash -c 'java -jar spring-boot-simple-data-rest-0.1.0.jar
- 釋出生產映象
docker push localhost:5000/java_simple_prod
- 啟動生產映象
make deploy-production-local
Makefile
start-docker-registry:
- docker run -d -p 5000:5000 -v /data/registry:/var/lib/registry --name registry --r
estart=always registry
build-docker-env:
docker build -t localhost:5000/maven dockers/maven
build-docker-prod-image:
docker build -t localhost:5000/java_simple_prod .
deploy-production-local:
- docker rm -f java_simple_prod
- docker run -d --name java_simple_prod -p 8000:8000 localhost:5000/java_simple_prod
Jenkins模式Blue Ocean
# Jenkinsfile https://github.com/agileworks-tw/spring-boot-sample
pipeline {
agent any
stages {
stage('checkout project') {
steps {
//git url: 'https://github.com/agileworks-tw/spring-boot-sample.git'
checkout scm
}
}
stage('check docker install and build env') {
steps {
sh "docker -v"
sh "docker-compose -v"
sh "docker ps"
sh "make start-docker-registry"
sh "make build-docker-env"
}
}
stage('test project and serve') {
steps {
sh "docker-compose run --rm test"
sh "docker-compose up -d server"
}
post {
always {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
junit '**/target/surefire-reports/TEST-*.xml'
}
}
}
stage('wait for confirm') {
input {
message "Does staging at http://localhost:8000 look good?"
ok "Deploy to production"
submitter "admin"
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
}
}
steps {
echo "Hello, ${PERSON}, nice to meet you."
}
post {
always {
sh "docker-compose stop server"
}
}
}
stage('deploy project') {
when {
branch 'master'
}
steps {
sh "docker-compose run --rm package"
sh "make build-docker-prod-image"
sh "docker push localhost:5000/java_sample_prod"
sh "make deploy-production-local"
}
}
}
}
擴充
- agent docker所有應用在指定映象中執行
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
checkout scm
}
}
}
- post當執行完有錯誤或者成功時執行
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
}
}
- input parameter使用者輸入
stage('wait for input'){
input {
......
}
}
- when condition
stage('deploy project'){
when{
branch 'master'
}
steps{
......
}
}
相關文章
- Jenkins+GitLab+SonnarQube搭建CI/CD全流程JenkinsGitlab
- CI與CD之Docker上安裝JenkinsDockerJenkins
- Jenkins與Docker的自動化CI/CD實戰(一)JenkinsDocker
- Jenkins 與 Kubernetes 的 CI 與 CD & Git + Maven + Docker+KubectlJenkinsGitMavenDocker
- Docker 整合 Jenkins Gitlab 實現 CI/CDDockerJenkinsGitlab
- Jenkins2 實現持續交付初次演練(MultiJob,Pipeline,Blue Ocean)Jenkins
- 使用Kubernetes-Jenkins實現CI/CDJenkins
- 命令列方式管理NETBACKUP命令列
- 在Jenkins的幫助下讓我們的應用CI與CDJenkins
- 詳解CI、CD & CD
- jenkins如何構建github上的程式碼(ci cd)JenkinsGithub
- CI Weekly #14 | 如何構建合適的 CI/CD 開發流程?
- Jenkins 中 cd 與 dirJenkins
- SAP HANA命令列方式恢復命令列
- maven jar包下載命令列方式MavenJAR命令列
- CI/CD理解
- .Net在Windows上使用Jenkins做CI/CD的那些事WindowsJenkins
- 還在用Jenkins?試試Gitlab的CI/CD功能吧JenkinsGitlab
- 手把手教你部署前端專案CI/CD Jenkins 篇前端Jenkins
- 透過 Drone CLI 手動觸發 CI/CD 流程
- Artisan 命令列 2種實現方式命令列
- 使用Jenkins+Blue Ocean 持構建自動化部署之安卓原始碼打包、測試、郵件通知Jenkins安卓原始碼
- 一篇文章瞭解CI/CD管道全流程
- pyautocad 命令列方式操作 CAD命令列
- Jenkins在Java web專案CI/CD中的簡單應用JenkinsJavaWeb
- 使用Git建立本地倉庫(命令列方式&圖形化介面方式)Git命令列
- CloudFoundry命令列和Kubernetes命令列的Restful API消費方式Cloud命令列RESTAPI
- 使用Docker方式安裝JenkinsDockerJenkins
- 命令列查詢天氣的正確方式命令列
- 【Kubernetes系列】第8篇 CI/CD之全流程實踐
- DevOps下微服務架構連續交付部署CI/CD流程dev微服務架構
- 基於OpenStack+Docker設計與實現CI/CD——基於Docker技術的CI&CD實踐Docker
- 基於Kubernetes構建企業Jenkins master/slave CI/CD平臺JenkinsAST
- CI Weekly #8 | CI/CD 技能進階路線
- Gitlab-CI/CD 2Gitlab
- 前端初探 Gitlab CI/CD前端Gitlab
- java ci/cd環境搭建Java
- 什麼是 CI/CD? - reddit