|NO.Z.00380|——————————|CloudNative|——|KuberNetes&CI/CD.V18|-----------------------------------------------------------|Jenkins.v06|Jenkins下建立pod.v03|
阿新 • • 發佈:2022-04-01
[CloudNative:KuberNetes&CI/CD.V18] [Applications.KuberNetes] [圖形化建立Jenkinsfile|k8s動態JenkinsSlave|建立Jenkinsfile|pipeline模板|建立Job|推送專案包到gitlab|]
一、Jenkins下建立pod
二、配置環境變數### --- 新增檢視: ~~~ Jenkins——>Dashboard——>ALL——>加號:View name:Java——>List View——>OK ~~~ ——>Name:Java——>Description:Java應用——>OK
### --- 配置環境變數: ~~~ Jenkins——>Dashboard——>New Item——>Enter an item name:spring-cloud-demo——>Pipeline——>OK:Add to current view新增到當前檢視——> ~~~ ——>General——>This project is parameterized——> ~~~ ——>變數一:Add Parameter:List Git Branches(and more)——>Name:BRANCH ~~~ ——>Repository URL:[email protected]:kubernetes-guide/spring-cloud-demo.git ~~~ ——>Credentials:gitlab key——>Parameter Type:Branch——>Advanched ~~~ ——>Branch Filter:refs/heads/(.*)——>Default Value:master——>END
三、配置pipeline~~~ ——>變數二:Add Parameter:Hidden Parameter——>Name:REPO_URL——>Default Value:[email protected]:kubernetes-guide/spring-cloud-demo.git——>END ~~~ ——>變數三:Add Parameter:Multi-line StringParameter——>Name:BUILD_COMMAND——>Default Value:mvn clean package -DskipTests——>Description:編譯命令——>END ~~~ ——>變數四:Add Parameter:Hidden Parameter——>Name:HARBOR_ADDRESS——>Default Value:registry.cn-beijing.aliyuncs.com——>END ~~~ ——>變數五:Add Parameter:Hidden Parameter——>Name:REGISTRY_DIR——>Default Value:java-demo——>END ~~~ ——>變數六:Add Parameter:Hidden Parameter——>Name:IMAGE_NAME——>Default Value:spring-cloud-demo-eureka——>END ~~~ ——>變數七:Add Parameter:Hidden Parameter——>Name:CLUSTER——>Default Value:test——>END ~~~ ——>變數八:Add Parameter:Hidden Parameter——>Name:KUBECONFIG_PATH——>Default Value:/mnt/.kube/multi-cluster.yaml——>END ~~~ ——>變數九:Add Parameter:Hidden Parameter——>Name:DEPLOY_TYPE——>Default Value:deployment——>END ~~~ ——>變數十:Add Parameter:Hidden Parameter——>Name: DEPLOY_LABEL——>Default Value:app=spring-cloud-demo-eureka——>END ~~~ ——>變數十一:Add Parameter:Hidden Parameter——>Name:CONTAINER_NAME——>Default Value——>spring-cloud-demo-eureka——>END ~~~ ——>變數十二:Add Parameter:Hidden Parameter——>Name:NAMESPACE——>Default Value:java-test——>END ~~~ ——>變數十二:Add Parameter:Choice Parameter——>Name:DEPLOY——>Choices:true false——>Description:是否進行部署操作——>Save——>END
### --- 配置pipeline
~~~ ——>Pipeline配置:——>Definition:Pipeline script from SCM——>SCM:Git
~~~ ——>Repositories:Repository URL:[email protected]:kubernetes-guide/jenkinsfile.git
~~~ ——>Credentials:gitlab key
~~~ ——>Branches to build——>Branch Specifier(blank for 'any'):*/java-pipeline
~~~ ——>Script Path:Jenkinsfile
~~~ ——>Save——>——>END
四、更改spring-cloud-demo專案地址
### --- 更改spring-cloud-demo專案地址
~~~ # openJDK:若公司的程式碼不是基於openJDK開發的,是基於oracle開發的,
~~~ 大部分是基於oracle開發的,有的會用到oracle的庫,但是openJDK是沒有的,會導致程式起不來。
~~~ 或者把oracle:jdk安裝到Java映象中
~~~ 也可以使用hub中的jre或者jdk映象就可以,跑一個映象的話使用jre映象就可以,
~~~ 若是進行構建需要用到jdk,jre會小一點
~~~ 啟動命令沒有寫入在dockerfile中,會通過deployment檔案注入進去
### --- 檢視當前專案在哪個分支下
[root@k8s-master01 spring-cloud-demo]# git status
# On branch master
nothing to commit, working directory clean
[root@k8s-master01 spring-cloud-demo]# git remote -v
origin [email protected]:kubernetes-guide/spring-cloud-demo.git (fetch)
origin [email protected]:kubernetes-guide/spring-cloud-demo.git (push)
### --- 新建分支pipeline-test
[root@k8s-master01 spring-cloud-demo]# git checkout -b pipeline-test
Switched to a new branch 'pipeline-test'
### --- 刪除無用的專案
[root@k8s-master01 spring-cloud-demo]# rm -rf spring-cloud-commons/ spring-cloud-gateway/ spring-cloud-nacos-discovery/ spring-cloud-user/ LICENSE pom.xml README.md
### --- 將eureka專案拷貝到當前目錄下
[root@k8s-master01 spring-cloud-demo]# mv spring-cloud-eureka/* .
[root@k8s-master01 spring-cloud-demo]# ls
logs pom.xml spring-cloud-eureka spring-cloud-eureka-0.0.1-SNAPSHOT.jar src target
[root@k8s-master01 spring-cloud-demo]# rm -rf spring-cloud-eureka spring-cloud-eureka-0.0.1-SNAPSHOT.jar target/ logs/
### --- 寫入dockerfile
[root@k8s-master01 spring-cloud-demo]# vim Dockerfile
#openJDK,oracle:jdk jre jdk
FROM registry.cn-beijing.aliyuncs.com/citools/maven:3.5.3
COPY target/*.jar /opt
EXPOSE 8080
五、push到gitlab中### --- push到gitlab中
[root@k8s-master01 spring-cloud-demo]# ls
Dockerfile pom.xml src
[root@k8s-master01 spring-cloud-demo]# git add . --all
[root@k8s-master01 spring-cloud-demo]# git commit -am "added Dockerfile"
[root@k8s-master01 spring-cloud-demo]# git config --global user.email "[email protected]"
[root@k8s-master01 spring-cloud-demo]# git config --global user.name "yanqi"
[root@k8s-master01 spring-cloud-demo]# git push origin pipeline-test
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 416 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for pipeline-test, visit:
remote: http://gitlab.test.com/kubernetes-guide/spring-cloud-demo/-/merge_requests/new?merge_request%5Bsource_branch%5D=pipeline-test
remote:
To [email protected]:kubernetes-guide/spring-cloud-demo.git
* [new branch] pipeline-test -> pipeline-test
六、更改配置變數的配置引數
### --- 更改配置變數的配置引數
~~~ # 可以從gitlab中獲取到資料,說明這個job是可以正常訪問到生成的映象包的
~~~ ——>變數三:Add Parameter:Multi-line StringParameter——>Name:BUILD_COMMAND
~~~ ——>Default Value:mvn clean package-Dskip Tests——>Description:編譯命令——>END
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)