[英]Is it possible to call Gitlab Pipeline from Jenkins pipeline and then wait for the results from the Gitlab
我有用於運行自動化測試的 Gitlab Pipeline(它更像是一個微服務 - 它根據輸入變量運行測試套件)。
現在我有一個建築物的 Jenkins 管道,我想用調用 Gitlab 來替換“自動化測試”階段。
我現在所做的就是調用 Gitlab 的 webhook 來觸發自動化套件。 但由於它是一個 webhook,即使 GitLab 管道失敗,自動化測試階段也總是“通過”。
是否可以在 Jenkins 中等待結果,或者是否有任何現有的軟件來處理它?
謝謝!
更新:
pipeline {
stages {
stage('calculate build and deployment') {
steps {
script {
...
}
stage('checkArtifactory') {
steps {
script {
...
}
}
}
stage('unit test') {
steps {
script {
...
}
}
}
stage("deploy") {
stages {
stage('dev deploy') {
steps{
script {
..
}
}
}
stage('automated tests') {
steps{
script {
!!!CURL REQUEST TO GITLAB TO TOUCH A WEBHOOK
}
}
}
}
}
而不是使用 webhook。 也許你可以考慮使用Gitlab API 。 例如,如果我假設您在通過 Gitlab API 觸發 Pipeline 后獲得了 Run ID,您可以再次調用來檢查 Pipeline 的狀態並繼續執行此操作直到執行結束。 這看起來像下面的那個。 除了使用 Groovy,您也可以使用 shell 腳本來實現相同的功能。
stage('automated tests') {
steps{
script {
def buildId = httpRequest 'http://GITLAB_PIPELINE_TRIGGER_URL' // Here I'm using HTTP Request plugin in Jenkins
timeout(time: 300, unit: 'SECONDS') { // To make sure we don't wait forever
def doCheck = true
while(doCheck) {
def response = httpRequest 'http://GITLAB_JOB_STATUS_URL/$buildId'
if(response == "Success") {
doCheck = false
} else if (response == "Failure") {
error "GITLAB Job failed"
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.