2016-04-25 9 views
25

यहाँ कोड मैंएक जेनकींस पाइपलाइन मंच के रूप में पूरे काम में नाकाम रहने के बिना विफल रहा है दिखाएँ

node { 
    stage 'build' 
    echo 'build' 

    stage 'tests' 
    echo 'tests' 

    stage 'end-to-end-tests' 
    def e2e = build job:'end-to-end-tests', propagate: false 
    result = e2e.result 
    if (result.equals("SUCCESS")) { 
     stage 'deploy' 
     build 'deploy' 
    } else { 
     ?????? I want to just fail this stage 
    } 
} 

साथ खेल रहा हूँ वहाँ मुझे 'के रूप में एंड-टू-एंड-परीक्षण' चरण को चिह्नित करने के लिए किसी भी तरह से है पूरी नौकरी में असफल होने के बिना असफल रहा? झूठा प्रचार करें बस मंच को हमेशा सत्य के रूप में चिह्नित करता है, जो कि मैं नहीं चाहता हूं, लेकिन सही अंक को प्रचार के रूप में प्रचारित करता हूं जो मैं नहीं चाहता हूं।

उत्तर

12

JENKINS-26522 जैसा लगता है।

if (result.equals("SUCCESS")) { 
    stage 'deploy' 
    build 'deploy' 
} else { 
    currentBuild.result = e2e.result 
    // but continue 
} 
+2

वहाँ ठीक इसके विपरीत करने के लिए कोई रास्ता नहीं है । लाल रंग के साथ असफल चरण को चिह्नित करने के लिए, लेकिन नीली रंग के साथ निर्माण (उस गेंद) की स्थिति? – Sviatlana

+0

धन्यवाद) यह मेरा समय बचाया – gokareless

+0

हाय @ स्वीटलाना क्या आप इसे पार करने में सक्षम थे? i.e लाल रंग के साथ असफल चरण चिह्नित करने के लिए? – user3768904

2

आप एक स्पष्ट कार्य असफल, इस तरह के चरण में 'श "कमांड मौजूद नहीं"' के रूप में जोड़ सकते हैं: वर्तमान में सबसे अच्छा तुम कर सकते हो एक समग्र परिणाम निर्धारित है।

if (result.equals("SUCCESS")) { 
    stage 'deploy' 
    build 'deploy' 
} else { 
    try { 
     sh "not exist command" 
    }catch(e) { 
    } 
} 
13

चरण अब एक ब्लॉक लेता है, इसलिए चरण को पकड़ने में मंच को लपेटें। मंच के अंदर कोशिश करें इसे सफल बनाता है।

पहले उल्लेख की गई नई सुविधा अधिक शक्तिशाली होगी। इस बीच में:

try { 
    stage('end-to-end-tests') { 
    node {  
     def e2e = build job:'end-to-end-tests', propagate: false 
     result = e2e.result 
     if (result.equals("SUCCESS")) { 
     } else { 
      sh "exit 1" // this fails the stage 
     } 
    } 
    } 
} catch (e) { 
    result = "FAIL" // make sure other exceptions are recorded as failure too 
} 

stage('deploy') { 
    if (result.equals("SUCCESS")) { 
     build 'deploy' 
    } else { 
     echo "Cannot deploy without successful build" // it is important to have a deploy stage even here for the current visualization 
    } 
} 
0

मैं हाल ही में एक समारोह है कि काम नाम की तरह नामक एक स्वयं के चरण में एक नौकरी excutes लिखने के लिए Vaza के जवाब Show a Jenkins pipeline stage as failed without failing the whole job टेम्पलेट के रूप में उपयोग करने के लिए कोशिश की। हैरानी की बात है यह काम किया, लेकिन हो सकता है कुछ ग्रूवी विशेषज्ञों एक नजर है यह :)

यह इस प्रकार से लगता है कि अगर नौकरियों में से एक निरस्त किया गया है पर: enter image description here

def BuildJob(projectName) { 
    try { 
     stage(projectName) { 
     node {  
      def e2e = build job:projectName, propagate: false 
      result = e2e.result 
      if (result.equals("SUCCESS")) { 
      } else { 
       error 'FAIL' //sh "exit 1" // this fails the stage 
      } 
     } 
     } 
    } catch (e) { 
     currentBuild.result = 'UNSTABLE' 
     result = "FAIL" // make sure other exceptions are recorded as failure too 
    } 
} 

node { 
    BuildJob('job1') 
    BuildJob('job2') 
} 
संबंधित मुद्दे