我的設定:主節點在 Linux 上運行,在 Windows 上運行代理。我想在代理上編譯一個庫,歸檔這些工件并將它們復制到主節點上,以創建一個與 Linux 編譯的二進制檔案一起發布的版本。
這是我的Jenkinsfile:
pipeline {
agent none
stages {
stage('Build-Windows') {
agent {
dockerfile {
filename 'docker/Dockerfile-Windows'
label 'windows'
}
}
steps {
bat "tools/ci/build.bat"
archiveArtifacts artifacts: 'build_32/bin/mylib.dll'
}
}
}
post {
success {
node('linux') {
copyArtifacts filter: 'build_32/bin/mylib.dll', flatten: true, projectName: '${JOB_NAME}', target: 'Win32'
}
}
}
}
我的問題是,當我第一次運行這個專案時,我收到以下錯誤
Unable to find project for artifact copy: mylib
但是當我評論該copyArtifacts塊并重新運行該專案時,它是成功的,并且我在專案概述中擁有可見的工件。在此之后,我可以重新啟用copyArtifacts,然后將按預期復制工件。
如何配置管道以便它可以在初始運行時訪問工件?
uj5u.com熱心網友回復:
該copyArtifacts功能通常用于在不同構建之間而不是在同一構建上的代理之間復制工件。相反,為了實作您想要的效果,您可以使用stash和unstash關鍵字,這些關鍵字專為在同一管道執行中傳遞來自不同代理的工件而設計:
stash:存盤一些檔案以供稍后在構建中使用。
保存一組檔案以供以后在同一管道運行中的任何節點/作業空間上使用。默認情況下,隱藏檔案在管道運行結束時被丟棄
unstash:恢復以前隱藏的檔案。
恢復一組先前隱藏在當前作業空間中的檔案。
在您的情況下,它可能如下所示:
pipeline {
agent none
stages {
stage('Build-Windows') {
agent {
dockerfile {
filename 'docker/Dockerfile-Windows'
label 'windows'
}
}
steps {
bat "tools/ci/build.bat"
// dir is used to control the path structure of the stashed artifact
dir('build_32/bin'){
stash name: "build_artifact" ,includes: 'mylib.dll'
}
}
}
}
post {
success {
node('linux') {
// dir is used to control the output location of the unstash keyword
dir('Win32'){
unstash "build_artifact"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/430864.html
