K8S學習之基礎五十四:jenkins新建測試流水線

jenkins新建測試流水線

新建任務
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

node('testak') {stage('第1步:從gitee上下載源代碼') {git url: "https://gitee.com/akang007/jenkins-sample"script {build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()}}stage('第2步:基于dockerfile文件制作鏡像') {sh "docker build -t 192.168.40.62/jenkins-demo/jenkins-demo:${build_tag} ."}stage('第3步:把鏡像上傳到harbor私有倉庫') {withCredentials([usernamePassword(credentialsId: 'dockerharbor', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {sh "docker login 172.16.80.140 -u ${dockerHubUser} -p ${dockerHubPassword}"sh "docker push 172.16.80.140/jenkins-demo/jenkins-demo:${build_tag}"}}stage('第4步:把pod部署到開發環境') {sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s-dev-harbor.yaml"sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s-dev-harbor.yaml"
//        sh "bash running-devlopment.sh"sh "kubectl apply -f k8s-dev-harbor.yaml  --validate=false"}	stage('第5步:把pod部署到測試環境') {	def userInput = input(id: 'userInput',message: '確定部署到測試環境嗎?輸入yes確定',parameters: [[$class: 'ChoiceParameterDefinition',choices: "YES\nNO",name: 'Env']])echo "This is a deploy step to ${userInput}"if (userInput == "YES") {sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s-qa-harbor.yaml"sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s-qa-harbor.yaml"
//            sh "bash running-qa.sh"sh "kubectl apply -f k8s-qa-harbor.yaml --validate=false"sh "sleep 6"sh "kubectl get pods -n qatest"sh "cd /home/jenkins/agent/workspace/jenkins-harbor"sh "/root/Python-3.12.5/python qatest.py"} else {//exit}}stage('第6步:pod部署到生產環境') {	def userInput = input(id: 'userInput',message: '確定部署到生產環境嗎?輸入yes確定',parameters: [[$class: 'ChoiceParameterDefinition',choices: "YES\nNO",name: 'Env']])echo "This is a deploy step to ${userInput}"if (userInput == "YES") {sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s-prod-harbor.yaml"sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s-prod-harbor.yaml"
//            sh "bash running-production.sh"sh "cat k8s-prod-harbor.yaml"sh "kubectl apply -f k8s-prod-harbor.yaml --record --validate=false"sh "cd /home/jenkins/agent/workspace/jenkins-harbor"sh "/root/Python-3.12.5/python smtp.py"}}
}

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

Skip to content
[Jenkins]Jenkins
查找 (?+K)
1
2
admin注銷
Dashboard
jenkins-harbor
#11
狀態
變更歷史
Console Output
View as plain text
編輯構建信息
刪除構建 ‘#11’
Timings
Git Build Data
回放
流水線步驟
Workspaces
上一次構建
Console Output
Started by user admin
[Pipeline] Start of Pipeline
[Pipeline] node
Agent test-p2tjd is provisioned from template test
---
apiVersion: "v1"
kind: "Pod"
metadata:annotations:kubernetes.jenkins.io/last-refresh: "1742977713779"labels:jenkins: "slave"jenkins/label-digest: "0d1a27dd84b68b7896a5df6f824a36e1721850f6"jenkins/label: "testak"kubernetes.jenkins.io/controller: "ttp___jenkins-service_jenkins-k8s_svc_cluster_local_8080x"name: "test-p2tjd"namespace: "jenkins-k8s"
spec:containers:- env:- name: "JENKINS_SECRET"value: "********"- name: "JENKINS_AGENT_NAME"value: "test-p2tjd"- name: "REMOTING_OPTS"value: "-noReconnectAfter 1d"- name: "JENKINS_NAME"value: "test-p2tjd"- name: "JENKINS_AGENT_WORKDIR"value: "/home/jenkins/agent"- name: "JENKINS_URL"value: "http://jenkins-service.jenkins-k8s.svc.cluster.local:8080/"image: "172.16.80.140/jenkins/jenkins.agent:v2"imagePullPolicy: "IfNotPresent"name: "jnlp"resources: {}securityContext:privileged: truetty: truevolumeMounts:- mountPath: "/home/jenkins/.kube"name: "volume-1"readOnly: false- mountPath: "/etc/docker/daemon.json"name: "volume-4"readOnly: false- mountPath: "/usr/bin/kubectl"name: "volume-3"readOnly: false- mountPath: "/usr/bin/docker"name: "volume-2"readOnly: false- mountPath: "/run/docker.sock"name: "volume-0"readOnly: false- mountPath: "/home/jenkins/agent"name: "workspace-volume"readOnly: falseworkingDir: "/home/jenkins/agent"hostNetwork: falsenodeSelector:kubernetes.io/os: "linux"restartPolicy: "Never"serviceAccountName: "jenkins-k8s-sa"volumes:- hostPath:path: "/run/docker.sock"name: "volume-0"- hostPath:path: "/usr/bin/docker"name: "volume-2"- hostPath:path: "/root/.kube"name: "volume-1"- emptyDir:medium: ""name: "workspace-volume"- hostPath:path: "/etc/docker/daemon.json"name: "volume-4"- hostPath:path: "/usr/bin/kubectl"name: "volume-3"Running on test-p2tjd in /home/jenkins/agent/workspace/jenkins-harbor
[Pipeline] {
[Pipeline] stage
[Pipeline] { (第1步:從gitee上下載源代碼)
[Pipeline] git
The recommended git tool is: NONE
No credentials specified
Cloning the remote Git repository
Cloning repository https://gitee.com/akang007/jenkins-sample> git init /home/jenkins/agent/workspace/jenkins-harbor # timeout=10
Fetching upstream changes from https://gitee.com/akang007/jenkins-sample> git --version # timeout=10> git --version # 'git version 2.39.5'> git fetch --tags --force --progress -- https://gitee.com/akang007/jenkins-sample +refs/heads/*:refs/remotes/origin/* # timeout=10> git config remote.origin.url https://gitee.com/akang007/jenkins-sample # timeout=10> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Checking out Revision df755ee1bbcf162fbfb6cadf8bb008039d6ccbb6 (refs/remotes/origin/master)
Commit message: "update smtp.py."> git rev-parse refs/remotes/origin/master^{commit} # timeout=10> git config core.sparsecheckout # timeout=10> git checkout -f df755ee1bbcf162fbfb6cadf8bb008039d6ccbb6 # timeout=10> git branch -a -v --no-abbrev # timeout=10> git checkout -b master df755ee1bbcf162fbfb6cadf8bb008039d6ccbb6 # timeout=10> git rev-list --no-walk df755ee1bbcf162fbfb6cadf8bb008039d6ccbb6 # timeout=10
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ git rev-parse --short HEAD
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (第2步:基于dockerfile文件制作鏡像)
[Pipeline] sh
+ docker build -t 172.16.80.140/jenkins-demo/jenkins-demo:df755ee .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.Install the buildx component to build images with BuildKit:https://docs.docker.com/go/buildx/Sending build context to Docker daemon  245.2kBStep 1/5 : FROM golang:1.10.4-alpine---> bd36346540f3
Step 2/5 : ADD . /go/src/app---> ffc6aa5f3db2
Step 3/5 : WORKDIR /go/src/app---> Running in 9823c707df6a---> Removed intermediate container 9823c707df6a---> 8de16f4e2759
Step 4/5 : RUN  go build -v -o /go/src/app/jenkins-app---> Running in 8383ac606d62
[91mapp
[0m ---> Removed intermediate container 8383ac606d62---> c56dc76e52d1
Step 5/5 : CMD ["./jenkins-app"]---> Running in a9cfa67f329d---> Removed intermediate container a9cfa67f329d---> de8f85fff5b3
Successfully built de8f85fff5b3
Successfully tagged 172.16.80.140/jenkins-demo/jenkins-demo:df755ee
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (第3步:把鏡像上傳到harbor私有倉庫)
[Pipeline] withCredentials
Masking supported pattern matches of $dockerHubPassword
[Pipeline] {
[Pipeline] sh
Warning: A secret was passed to "sh" using Groovy String interpolation, which is insecure.Affected argument(s) used the following variable(s): [dockerHubPassword]See https://jenkins.io/redirect/groovy-string-interpolation for details.
+ docker login 172.16.80.140 -u admin -p ****
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
[Pipeline] sh
+ docker push 172.16.80.140/jenkins-demo/jenkins-demo:df755ee
The push refers to repository [172.16.80.140/jenkins-demo/jenkins-demo]
4a8fd9bc91b9: Preparing
67781d6fba74: Preparing
ac1c7fa88ed0: Preparing
cc5fec2c1edc: Preparing
93448d8c2605: Preparing
c54f8a17910a: Preparing
df64d3292fd6: Preparing
c54f8a17910a: Waiting
df64d3292fd6: Waiting
93448d8c2605: Layer already exists
c54f8a17910a: Layer already exists
ac1c7fa88ed0: Layer already exists
cc5fec2c1edc: Layer already exists
df64d3292fd6: Layer already exists
67781d6fba74: Pushed
4a8fd9bc91b9: Pushed
df755ee: digest: sha256:6c80d0f4d2c2bb82ebb3286b874c21b1917ef381e348bcc600b05d5e7dbf899a size: 1785
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (第4步:把pod部署到開發環境)
[Pipeline] sh
+ sed -i s/<BUILD_TAG>/df755ee/ k8s-dev-harbor.yaml
[Pipeline] sh
+ sed -i s/<BRANCH_NAME>/null/ k8s-dev-harbor.yaml
[Pipeline] sh
+ kubectl apply -f k8s-dev-harbor.yaml --validate=false
deployment.apps/jenkins-demo created
service/demo created
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (第5步:把pod部署到測試環境)
[Pipeline] input
Input requested
Approved by admin
[Pipeline] echo
This is a deploy step to YES
[Pipeline] sh
+ sed -i s/<BUILD_TAG>/df755ee/ k8s-qa-harbor.yaml
[Pipeline] sh
+ sed -i s/<BRANCH_NAME>/null/ k8s-qa-harbor.yaml
[Pipeline] sh
+ kubectl apply -f k8s-qa-harbor.yaml --validate=false
deployment.apps/jenkins-demo created
service/demo created
[Pipeline] sh
+ sleep 6
[Pipeline] sh
+ kubectl get pods -n qatest
NAME                            READY   STATUS    RESTARTS   AGE
jenkins-demo-56fd75f4db-5nbst   1/1     Running   0          8s
[Pipeline] sh
+ cd /home/jenkins/agent/workspace/jenkins-harbor
[Pipeline] sh
+ /root/Python-3.12.5/python qatest.py
郵件發送成功!
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (第6步:pod部署到生產環境)
[Pipeline] input
Input requested
Approved by admin
[Pipeline] echo
This is a deploy step to YES
[Pipeline] sh
+ sed -i s/<BUILD_TAG>/df755ee/ k8s-prod-harbor.yaml
[Pipeline] sh
+ sed -i s/<BRANCH_NAME>/null/ k8s-prod-harbor.yaml
[Pipeline] sh
+ cat k8s-prod-harbor.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: jenkins-demonamespace: production
spec:replicas: 1selector:matchLabels:app: jenkins-demotemplate:metadata:labels:app: jenkins-demospec:containers:- image: 172.16.80.140/jenkins-demo/jenkins-demo:df755eeimagePullPolicy: IfNotPresentname: jenkins-demoenv:- name: branchvalue: null
---
apiVersion: v1
kind: Service
metadata:name: jenkins-demonamespace: production
spec:selector:app: jenkins-demotype: NodePortports:- port: 18888targetPort: 18888nodePort: 31890
[Pipeline] sh
+ kubectl apply -f k8s-prod-harbor.yaml --record --validate=false
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/jenkins-demo created
service/jenkins-demo created
[Pipeline] sh
+ cd /home/jenkins/agent/workspace/jenkins-harbor
[Pipeline] sh
+ /root/Python-3.12.5/python smtp.py
郵件發送成功!
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Jenkins 中文社區
REST API
Jenkins 2.426.3

開發、測試、生產三個環境都部署了pod和svc,均可以通過訪問ip+port的方式訪問
在這里插入圖片描述
在這里插入圖片描述

在這里插入圖片描述
在這里插入圖片描述

在這里插入圖片描述
在這里插入圖片描述
收到郵件
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/74660.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/74660.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/74660.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SylixOS 中 select 原理及使用分析

1、select接口簡介 1.1 select接口使用用例 select 是操作系統多路 I/O 復用技術實現的方式之一。 select 函數允許程序監視多個文件描述符&#xff0c;等待所監視的一個或者多個文件描述符變為“準備好”的狀態。所謂的”準備好“狀態是指&#xff1a;文件描述符不再是阻塞狀…

Spring WebFlux之ServerWebExchange

ServerWebExchange 是 Spring WebFlux 中的一個核心接口&#xff0c;用于表示服務器端處理的 HTTP 請求和響應。它封裝了請求和響應的所有信息&#xff0c;并提供了相應的方法來操作這些信息。ServerWebExchange 在響應式編程模型中扮演著關鍵角色&#xff0c;支持非阻塞、異步…

Flutter 常見錯誤和坑

1. 狀態管理問題 StatefulWidget 生命周期誤用 // 錯誤&#xff1a;在 build 方法中修改狀態 override Widget build(BuildContext context) {setState(() { counter; }); // 會導致無限重建循環return Text($counter); }// 正確&#xff1a;在事件處理中修改狀態 Widget bui…

C++智能指針萬字詳細講解(包含智能指針的模擬實現)

在筆試&#xff0c;面試中智能指針經常出現&#xff0c;如果你對智能指針的作用&#xff0c;原理&#xff0c;用法不了解&#xff0c;那么可以看看這篇博客講解&#xff0c;此外本博客還簡單模擬實現了各種指針&#xff0c;在本篇的最后還應對面試題對智能指針的知識點進行了拓…

【Go】Go語言結構體筆記

整體介紹 雖然 Go 語言不是傳統意義上的面向對象語言&#xff0c;但它提供了結構體&#xff08;struct&#xff09;來組織數據&#xff0c;并且可以為結構體綁定方法&#xff0c;從而達到面向對象的部分效果。 關鍵知識點包括&#xff1a; 結構體定義與實例化 定義結構體時使用…

Three.js 快速入門教程【十八】射線拾取模型——鼠標點擊屏幕選中模型或物體

系列文章目錄 Three.js 快速入門教程【一】開啟你的 3D Web 開發之旅 Three.js 快速入門教程【二】透視投影相機 Three.js 快速入門教程【三】渲染器 Three.js 快速入門教程【四】三維坐標系 Three.js 快速入門教程【五】動畫渲染循環 Three.js 快速入門教程【六】相機控件 Or…

Object.defineProperty()Proxy詳解(Vue23數據劫持實現)

底層原理&#x1f447;&#x1f3ff; 總結一下&#xff0c;結構應該包括&#xff1a; 1. 方法的基本作用和參數。 2. 數據描述符和存取描述符的區別。 3. 屬性定義的內部處理流程。 4. 在Vue中的應用實例。 5. 常見錯誤和正確實踐。 每個部分都要結合搜索結果的信息&…

MySQL 進階語法:函數、約束、多表查詢、事務

目錄 一、MySQL 常用函數 1. 字符串函數 1.1 基本字符串操作 1.2 字符串截取與處理 1.3 字符串搜索與替換 2. 數值函數 2.1 基本數學運算 2.2 數學計算 2.3 隨機數與符號 3. 日期時間函數 3.1 獲取當前時間 3.2 日期時間計算 3.3 日期時間提取 3.4 日期時間格式化…

第 12 章(番外)| Solidity 安全前沿趨勢 × 審計生態 × 職業路徑規劃

&#x1f310; 第 12 章&#xff08;番外&#xff09;| Solidity 安全前沿趨勢 審計生態 職業路徑規劃 ——做得了審計&#xff0c;也接得了項目&#xff0c;走進 Web3 安全工程師的職業實戰地圖 ? 本章導讀 Solidity 安全&#xff0c;不只是代碼安全、業務安全、審計安全…

1、pytest基本用法

目錄 先給大家分享下學習資源 1. 安裝pytest 2. 編寫用例規則 3. 執行用例 最近在學習pytest的用法 并且用這套框架替換了原來的unittest&#xff0c; 同是測試框架 確實感覺到pytest更加便捷 這邊分享給大家我得學習心得 先給大家分享下學習資源 1 官方文檔 pytest 官方…

【sylar-webserver】5 協程調度模塊

文章目錄 設計思路三種協程的切換 協程調度模塊&#xff0c;需要把前面的線程模塊和協程模塊結合使用 ~ 設計思路 構造函數定義 線程池 基本信息。start()&#xff0c;創建線程池&#xff0c;每個線程創建都執行 run()。每個線程在 run() 里&#xff0c;查找任務隊列 m_tasks…

Go 語言規范學習(1)

文章目錄 IntroductionNotation示例&#xff08;Go 語言的 if 語句&#xff09;&#xff1a; Source code representationCharacters例子&#xff1a;變量名可以是中文 Letters and digits Lexical elementsCommentsTokensSemicolons例子&#xff1a;查看程序所有的token Ident…

探索抓包利器ProxyPin,實現手機APP請求抓包,支持https請求

以下是ProxyPin的簡單介紹&#xff1a; - ProxyPin是一個開源免費HTTP(S)流量捕獲神器&#xff0c;支持 Windows、Mac、Android、IOS、Linux 全平臺系統- 可以使用它來攔截、檢查并重寫HTTP(S)流量&#xff0c;支持捕獲各種應用的網絡請求。ProxyPin基于Flutter開發&#xff0…

深度學習3-pytorch學習

深度學習3-pytorch學習 Tensor 定義與 PyTorch 操作 1. Tensor 定義&#xff1a; Tensor 是 PyTorch 中的數據結構&#xff0c;類似于 NumPy 數組。可以通過不同方式創建 tensor 對象&#xff1a; import torch# 定義一個 1D Tensor x1 torch.Tensor([3, 4])# 定義一個 Fl…

深入淺出Spring-Boot-3.x.pdf

通過網盤分享的文件&#xff1a;深入淺出Spring-Boot-3.x.pdf 鏈接: https://pan.baidu.com/s/10ZkhmeIXphEwND9Rv4EBlg?pwduatm 提取碼: uatm

springboot啟動事件CommandLineRunner使用

什么是CommandRunner CommandRunner是springboot啟動完成時會調用的一個runner 啟動參數會傳遞到這個runner 我們能用來做一些初始化工作和緩存預熱等工作 ApplicationRunner VS CommandRunner? 這兩個Runner作用一樣 只是得到的啟動參數格式不一樣 前者是一個Argument對象…

數據可視化TensorboardX和tensorBoard安裝及使用

tensorBoard 和TensorboardX 安裝及使用指南 tensorBoard 和 TensorBoardX 是用于可視化機器學習實驗和模型訓練過程的工具。TensorBoard 是 TensorFlow 官方提供的可視化工具&#xff0c;而 TensorBoardX 是其社區驅動的替代品&#xff0c;支持 PyTorch 等其他框架。以下是它…

藍橋杯C++基礎算法-多重背包

這段代碼實現了一個多重背包問題的動態規劃解法。多重背包問題與完全背包問題類似&#xff0c;但每個物品有其數量限制。以下是代碼的詳細思路解析&#xff1a; 1. 問題背景 給定 n 個物品&#xff0c;每個物品有其體積 v[i]、價值 w[i] 和數量 s[i]&#xff0c;以及一個容量為…

【SUNO】【AI作詞】【提示詞】

仿寫歌詞提示詞模板&#xff08;升級版&#xff09; 一、仿寫目標 風格定位 音樂風格&#xff1a; [填寫目標風格&#xff0c;如&#xff1a;民謠/流行/古風/電子/爵士等]參考案例&#xff1a;如《成都》的敘事民謠&#xff0c;《孤勇者》的勵志流行。 情感基調&#xff1a; […

26考研——樹與二叉樹_樹與二叉樹的應用(5)

408答疑 文章目錄 三、樹與二叉樹的應用哈夫曼樹和哈夫曼編碼哈夫曼樹的定義概念帶權路徑長度&#xff08;WPL&#xff09;計算示例分析 哈夫曼樹的構造算法描述哈夫曼樹的性質示例 哈夫曼編碼Huffman樹的編碼規則Huffman樹的構建過程前綴編碼前綴編碼的分析及應用 Huffman樹的…