2017-04-12 69 views
0

我無法得到一個shell命令在一個階段來完成我已經定義:管道一步遇到問題解決文件路徑

stages { 
    stage('E2E Tests') { 
     steps { 
      node('Protractor') { 
       checkout scm 
       sh ''' 
        npm install 
        sh 'protractor test/protractor.conf.js --params.underTestUrl http://192.168.132.30:8091' 
       ''' 
      } 
     } 
    } 
} 

shell命令問題量角器調用,它需要一個配置文件中的說法,但當量角器試圖檢索它時,找不到該文件。

如果我從checkout scm步驟中查看工作空間目錄中檢出回購庫的位置,我可以看到測試目錄存在,並且存在配置文件sh步驟正在引用。

所以我不確定爲什麼找不到文件。

我想過要驗證量角器命令發出時可以看到的文件。

因此,像:

stages { 
    stage('E2E Tests') { 
     steps { 
      node('Protractor') { 
       checkout scm 
       def files = findFiles(glob: 'test/**/*.conf.js') 
       sh ''' 
        npm install 
        sh 'protractor test/protractor.conf.js --params.underTestUrl http://192.168.132.30:8091' 
       ''' 
       echo """${files[0].name} ${files[0].path} ${files[0].directory} ${files[0].length} ${files[0].lastModified}""" 
      } 
     } 
    } 
} 

但這並不工作,我不認爲findFiles可以在某個步驟中使用嗎?

任何人都可以提供有關可能會發生什麼的任何建議嗎?

感謝

+1

爲什麼你在'sh'裏面有'sh'? –

+0

我意識到,在發佈問題後不久,我現在感到啞巴! – mindparse

回答

0

做你試圖(查看是否該文件實際上是存在),你可以在腳本中包裹findFiles調試(確保您的迴音是失敗的步驟之前進行)或使用基本在這樣的「sh」步驟中找到:

stages { 
    stage('E2E Tests') { 
    steps { 
     node('Protractor') { 
     checkout scm 

     // you could use the unix find command instead of groovy's findFiles 
     sh 'find test -name *.conf.js' 

     // if you're using a non-dsl-step (like findFiles), you must wrap it in a script 
     script { 
      def files = findFiles(glob: 'test/**/*.conf.js') 
      echo """${files[0].name} ${files[0].path} ${files[0].directory} ${files[0].length} ${files[0].lastModified}""" 
      sh ''' 
      npm install 
      sh 'protractor test/protractor.conf.js --params.underTestUrl http://192.168.132.30:8091' 
      ''' 
     } 
     } 
    } 
    } 
} 
+0

感謝凱文,事實證明這是我愚蠢 - 我有一個SH內! – mindparse

+0

幸運的是我複製並粘貼到我的答案。 :d – burnettk