3

I have a pipeline which has 2 steps:

the first one is doing a "build" job with an error - the project name isn't correct (test3 instead of test)

and a second step which prints 1

right now there are 2 problems with this pipeline,

1) the first stage is green although the job fails for this I created this question: how to fix - stageResult set to FAILURE but still get success in jenkins

2) I want to be able to read the build job and find the string with the error:

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\pipeline             testing
[Pipeline] {
[Pipeline] stage
[Pipeline] { (1)
[Pipeline] catchError
[Pipeline] {
[Pipeline] build (Building build)
Scheduling project: build
Starting building: build #102
[Pipeline] }
ERROR: build #102 completed with status FAILURE (propagate: false to     ignore)
[Pipeline] // catchError
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
...

how can I add to my pipeline: if you see this line: "Recived HTTP/400: Bad Request , "Project not found." which is inside the build (freestyle) itself

make this a success, otherwise make this stage failure

this is the pipeline as it is now:

pipeline {
    agent any
    stages 
    {
        stage('1') 
        {
            steps 
            {
                catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')
                {
                    build job: 'build',parameters: [string(name: 
'Project_Name', value: 'test3'), 
                    string(name: 'Environment_Name', value: 'Dev_Env_1')]    
                }

            }
        }    
        stage('2') 
        {
            steps
            {
                echo '1'
            }
        }
    }
}
JHON SMITH
  • 103
  • 1
  • 1
  • 6

1 Answers1

1

Good Topic Choice JOHN SMITH.I also have the similar question Have you tried to handle it like this?

try { stage('some-stage') { //do something } } catch (Exception e) { echo "Stage failed, but we continue" } try { stage("some-other-stage") { // do something } } catch (Exception e) { echo "Stage failed, but we still continue" }
tituszban
  • 4,797
  • 2
  • 19
  • 30