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

106 views
Skip to first unread message

Jakub Michalec

unread,
Jan 12, 2018, 9:09:40 AM1/12/18
to Jenkins Users
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?

Reply all
Reply to author
Forward
0 new messages