2017-05-03 38 views
1

我有一些代碼需要在不同的操作系統上運行(構建,測試和實際包,但例如只是運行tox)。目前我Jenkinsfile看起來像這樣:Jenkinsfile和多個節點

pipeline { 

    // Where to run stuff. 
    agent { 
     node { 
      label 'CentOS7' 
      customWorkspace '/home/build/jenkins/workspace/pipelines/ook' 
     } 
    } 

    // What to run goes here. 
    stages { 
     stage('Tox') { 
      steps { 
       sh 'tox -v --recreate' 
      } 
     } 
    } 

    // Clean up after ourselves. 
    post { 
     failure { 
      mail subject: "\u2639 ${env.JOB_NAME} (${env.BUILD_NUMBER}) has failed", 
        body: """Build ${env.BUILD_URL} is failing! 
    Somebody should do something about that\u2026""", 
          to: "[email protected]", 
        replyTo: "[email protected]", 
         from: '[email protected]' 
      } 
     } 
    } 
} 

的中間位,我想在兩個不同的nodes運行:一個用於OS 1,一個用於OS 2.

我該怎麼辦呢?

回答

1

當然,你會想以某種方式標記你的奴隸節點。我沒有查找什麼是tox,但可能像'os_linux'和'os_mac',然後你可以使用Jenkinsfile中的node步驟在每個slave的上下文中運行一些命令。所以你的弓形蟲階段可能類似於:

stage('Tox') { 
    steps { 
    node('os_linux') { 
     sh 'tox -v --recreate' 
    } 
    node('os_mac') { 
     sh 'tox -v --recreate' 
    } 
    } 
} 

這將在連續運行的任務,並Jenkinsfile語法還支持在不同的節點上並行執行這兩個TOX命令。使用Jenkins UI左側導航欄中的「Pipeline Syntax」(管道語法)鏈接(僅限於管道作業),與nodeparallel一起玩。搖滾。

+0

任何想法如何在這種情況下定義'customWorkspace'? – Sardathrion

+0

另外,我應該[更詳細地閱讀可怕的文檔](https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents)...☹ – Sardathrion

+0

[Tox旨在自動化和標準化測試在Python中。它是放寬Python軟件打包,測試和發佈流程的更大願景的一部分。](https://tox.readthedocs.io/en/latest/)。 – Sardathrion