在 VS Code 中校驗 Jenkinsfile
在日常工作中,我經常需要建立或修改很多 Jenkinsfile,有時還會發生錯誤。這是一個非常繁瑣的流程——修改 Jenkinsfile,提交、推送,然後等 Jenkins 提醒你少加了一個括號。
Command-line Pipeline Linter( ofollow,noindex" target="_blank">https://jenkins.io/doc/book/pipeline/development /) 可以有效地減少編寫 Jenkinsfile 所需要的除錯時間,但是它也有一些不方便的地方。你需要使用像 curl 或 ssh 的工具來連線你的 Jenkins,還需要正確地記住驗證 Jenkinsfile 的命令。儘管如此,對我來說,這個方案還是不盡如人意。
鑑於每天都會使用 VS Code,於是我開始著手為此研發外掛,使得校驗 Jenkinsfile 變得更加友好。
Jenkins Pipeline Linter Connector 的作用就是,把當前開啟的檔案推送到你的 Jenkins,然後在 VS Code 中顯示校驗結果。
你可以在 VS Code 外掛瀏覽器中或通過下面的地址找到該外掛 https://marketplace.visualstud ... ector 。
該外掛會在 VS Code 中新增四個配置選項,你必須要使用這些選項來配置用於驗證的 Jenkins。
jenkins.pipeline.linter.connector.url 是 Jenkins 期望的 POST 請求地址,包含你要校驗的 Jenkinsfile 檔案。通常為 http://<your_jenkins_server:por t>/pipeline-model-converter/validate。
jenkins.pipeline.linter.connector.user 允許指定你的 Jenkins 使用者名稱。
jenkins.pipeline.linter.connector.pass 允許指定你的 Jenkins 密碼。
jenkins.pipeline.linter.connector.crumbUrl 當你的 Jenkins 啟用了 CRSF 時必須指定。通常為 http://<your_jenkins_server:por t>/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)。