Home > Mobile >  Jenkins Pipeline failed
Jenkins Pipeline failed

Time:07-12

I am running a scripted version of the Jenkins pipeline. It ran through all the stages except the last stage. It failed every time.

Here is the Jenkins code that keep on failing:

    stage('Deploy Production') {
        echo "Deploy Prod on: ${env.BRANCH_NAME}"
        try {
            if (env.BRANCH_NAME == 'master'){
                withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'XX',
                                  usernameVariable: 'XXXXX', passwordVariable: 'XXXXXX']]) {
                    sh 'npm run build-prod-ci'
                    sh 'cf login -u ${XXXXX} -p ${XXXXXX} -a website.com -o XXX -s XXXX'
                    sh 'cf blue-green-deploy Dashboard'
                    sh 'cf delete Dashboard-old -f'
                }
            }
        } finally {
            deleteDir()
            sh 'cf logout'
        }
    }

This is the printout and the error message. Any help in resolving this issue is appreciated.

Plugin blue-green-deploy 1.3.0 successfully installed.
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Development)
[Pipeline] echo
Deploy Dev on: master
[Pipeline] deleteDir
[Pipeline] sh
  cf logout
Logging out ...
OK
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Production)
[Pipeline] echo
Deploy Prod on: master
[Pipeline] withCredentials
Masking supported pattern matches of $XXXXXX
[Pipeline] {
[Pipeline] sh
  npm run build-prod-ci
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /v/wl/ws/Dashboard_master/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/v/wl/ws/Dashboard_master/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /v/wl/wsp/Dashboard_master/.npm/_logs/2022-07-06T22_43_57_239Z-debug.log
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] deleteDir
[Pipeline] sh
  cf logout
Logging out ...
OK
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 254

Previous stages with npm commands worked fine. Here is an example of a stage that worked:

        stage('Run project tests and build') {
            echo "Run project tests and build on: ${env.BRANCH_NAME}"
            sh "npm run lint"
            //sh "npm run compodoc-ci"
            //sh "npm run test-coverage"
            sh "npm run build-dev-ci"
        }

CodePudding user response:

This issue was self inflicted, and the comments that was given above gave me some hints to arrive at the solution.

The problem was that I was moving the original Jenkins code (I think it's called Declarative Pipeline) over to this form (scripted pipeline?), and I converted the code below without thinking because Jenkins is not something I work with everyday...

steps {
    when {
        branch 'dev'
        }
    }
    post {
        always {
            deleteDir()

to

try {
    if (env.BRANCH_NAME == 'dev'){
        } finally {
            deleteDir()

Anyway, the command deleteDir() delete the directory, and therefore it can't find that file anymore.

Thanks for the help guys. Much appreciated.

Lesson: check your code to understand what's it's doing. Copy and paste will only help to a certain extent.

  • Related