Declarative Pipeline, how post build shoud work when chaining jobs?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Declarative Pipeline, how post build shoud work when chaining jobs?

Jakub Michalec
Hello,
I have job like below, createDeployment comes from sharedlibrary, and just calling 'build job' with passed params.

Triggered job (deployment) have post action to delete deployment if anything wrong happened. When deployment fail triggered job call post actions but only archiveArtifacts, cleaning deployment don't work.

Deployment job error like below (exit 1 is what I want to get when error occur in powershell script)

ERROR: script returned exit code 1
Finished: FAILURE


post action in above job it's a bit complicated, but still jenkins don't even run it ( I put simple println to check if it go into it)

@Library('MySharedLibrary') _

pipeline{
    agent { node { label 'some-label'} }

    stages {
        stage('Create Deployment') {
            steps {
                deleteDir()

                createDeployment branchName: "master",
                                 name: "runonmaster"
            }
        }

        ...

    post {
        always {
            sendNotifications currentBuild.result
        }
    }
}




post action in deployment job

        post {
            always {
                archiveArtifacts "${name}*.txt"
                
                script {
                    new NotificationSender().cloudNotify(buildStatus: currentBuild.result)
                }
            }
        }



new NotificationSender().cloudNotify() -> sending email, call job for remove deployment


But I get only artifacts

[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
Archiving artifacts
[Pipeline] step
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // ws
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
ERROR: script returned exit code 1
Finished: FAILURE

What goes wrong?


In powershell script, there's a check point, if for eq deployment already exists, throw exception

So, I wanted to catch status:

    def status = powershell returnStatus: true, script: """
    . .CreateDeploy.ps1
    Deploy -installationName $pipeline.name 
    """
    
    if(status != 0) { powershell ("Write-Error \"Ooops, an error occured\"") }

in jenkins log I get
1) Exception from powershell -> throw "deployment exists"
2) WriteError step -> Ooops, an error occured

How to make this post action to run?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/96bedaa0-3d9e-402a-830d-f53e893c13a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.