2016-07-14 45 views
0

我正在嘗試運行http調用來測試將要在jenkins機器上運行的活動web api。如何讓jenkins移動到下一階段,如果它的「終端」被阻止?

這是使用的管道腳本。

stage 'build' 
    node { 
     git url: 'https://github.com/juliomarcos/sample-http-test-ci/' 
     sh "npm install" 
     sh "npm start" 
    } 
stage 'test' 
    node { 
     sh "npm test" 
    } 

但是詹金斯會不會移動到測試一步。如何在Web應用程序完全啓動後運行npm test

回答

1

一種方法是在最後啓動一個&網絡應用程序,以便它將在後臺運行。即

npm start &

您可以嘗試NPM啓動的輸出重定向到一個文本文件是這樣的:在下一步

npm start > output.txt &

然後,循環下去,直到「啓動」消息可用的,是這樣的:

tail -f output.txt | while read LOGLINE 
do 
    [[ "${LOGLINE}" == *"listening on port"* ]] && pkill -P $$ tail 
done 

代碼沒有測試:)

+0

如果我這樣做,我怎麼能確定測試只會在應用程序完成其啓動過程後纔開始? –

+0

看到我的編輯,它可能會有所幫助 –