![](/img/trans.png)
[英]Couldn't find any revision to build. Verify the repository and branch configuration for this job. Why am I seeing this failure?
[英]Why am I not seeing terminal output in the Build Console for this Jenkinsfile?
對於為什么我在此Jenkinsfile的jenkinsSlack()函數中看不到echo()語句的輸出,我有些困惑。 這些階段肯定正在運行,因為我可以在Pipeline可視化中看到它們正在執行。
#!groovy
def slack_channel() {
try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
catch (MissingPropertyException e) { return '#nathan-webhooks' }
}
// simplify the generation of Slack notifications for start and finish of Job
def jenkinsSlack(type, channel=slack_channel()) {
echo("echo 'In jenkinsSlack()...")
echo("echo 'type specified as : ${type}'")
echo("echo 'channel specified as : ${channel}'")
if ( 'SUCCESS' == currentBuild.result ) {
slackSend channel: channel, color: 'good', message: "type: ${type}"
} else if ( 'FAILURE' == currentBuild.result ) {
slackSend channel: channel, color: 'danger', message:"type: ${type}"
} else {
slackSend channel: channel, color: 'warning', message: "type: ${type}"
}
// node - action starts here
node {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm', 'defaultFg': 2, 'defaultBg':1]) {
stage ("send Slack start message") {
checkout scm
jenkinsSlack('start')
}
stage("send Slack finish message") {
jenkinsSlack('finish')
}
} // AnsiColorBuildWrapper
}
謝謝
由於jenkinsSlack(type, channel=slack_channel())
僅返回slack_channel()
的值,而不執行包含echo的方法主體jenkinsSlack(type, channel=slack_channel())
因此缺少回顯消息。
這是詹金斯特定於CPS轉換的問題。 Jenkins管道腳本基於groovy,但在語法和用法方面有一些限制。 在此處查看更多詳細信息: https : //github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md#technical-design
可能的解決方法如下。
1,對slack_channel()
@NonCPS
注釋
@NonCPS
def slack_channel() {
try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
catch (MissingPropertyException e) { return '#nathan-webhooks' }
}
2.預先確定SLACK_CHANNEL
並將其傳遞給默認參數channel
:
def slack_channel() {
try { if ('' != SLACK_CHANNEL) { return SLACK_CHANNEL } }
catch (MissingPropertyException e) { return '#nathan-webhooks' }
}
SLACK_CHANNEL = slack_channel()
def jenkinsSlack(type, channel=SLACK_CHANNEL) {
echo type
echo channel
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.