SAP-archive / jenkins-pipelines

Jenkins pipeline implementations for Continuous Delivery.
Apache License 2.0
31 stars 21 forks source link

No Log output after neoDeploy failed #16

Open citoki opened 5 years ago

citoki commented 5 years ago

With the following Jenkinsfile wants to deploy the artifact to NEO, it fails and cannot write any logs.

@Library('piper-lib-os') _

node() {

  stage('prepare') {
      deleteDir()
      checkout scm
      setupCommonPipelineEnvironment script:this
  }

  stage('build') {
      mtaBuild script: this
  }

  stage('neoDeploy') {
      neoDeploy script: this
  }

}
ContainerConfig: [name:container-exec]
[Pipeline] container
[Pipeline] {
[Pipeline] echo
Unstash content: workspace-7ec3cfa4-6027-40b9-b452-2b092114de28
[Pipeline] unstash
[Pipeline] echo
[INFO][dockerExecute] Executing inside a Kubernetes Pod
[Pipeline] lock
Trying to acquire lock on [neoDeploy :eu1.hana.ondemand.com/acc1]
Lock acquired on [neoDeploy :eu1.hana.ondemand.com/acc1]
[Pipeline] {
[Pipeline] sh
+ mkdir -p logs/neo
[Pipeline] pwd
[Pipeline] withEnv
[Pipeline] {
[Pipeline] fileExists
[Pipeline] error
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] echo
Error while deploying to SAP Cloud Platform. Here are the neo.sh logs:
[Pipeline] sh
+ cat 'logs/neo/*'
cat: can't open 'logs/neo/*': No such file or directory
[Pipeline] }
Lock released on resource [neoDeploy :eu1.hana.ondemand.com/acc1]
[Pipeline] // lock
[Pipeline] sh
[Pipeline] stash
Stashed 61 file(s)
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] unstash
[Pipeline] libraryResource
[Pipeline] echo
----------------------------------------------------------
--- An error occurred in the library step: dockerExecuteOnKubernetes
----------------------------------------------------------

The following parameters were available to the step:
***
[script:WorkflowScript@1c3856a5, dockerImage:s4sdk/docker-neo-cli, dockerPullImage:true, stashContent:[workspace-7ec3cfa4-6027-40b9-b452-2b092114de28]]
***

The error was:
***
hudson.AbortException: script returned exit code 1
***

Further information:
* Documentation of library step dockerExecuteOnKubernetes: https://sap.github.io/jenkins-library/steps/dockerExecuteOnKubernetes/
* Source code of library step dockerExecuteOnKubernetes: https://github.com/SAP/jenkins-library/blob/master/vars/dockerExecuteOnKubernetes.groovy
* Library documentation: https://sap.github.io/jenkins-library/
* Library repository: https://github.com/SAP/jenkins-library/
marcusholl commented 5 years ago

I refer to commit 78400cad9bdce2b1b638726eee16ee9e03202c9f in the piper-lib.

Tried to dive into that issue:

Findings up to now: 1.) we see the sh command for mkdir -p logs/neo. A corresponding folder does not exist in the workspace. Maybe we are in another workdir when creating the folder -> further investigation needed. 2.) we see the pwd statement. This corresponds to vars/neoDeploy#112 3.) we see the the withEnv. This corresponds to vars/neoDeploy#112 4.) we see the fileExists. This corresponds to src/com/sap/piper/StepAssertions#10. 5.) we see error. This corresponds to src/com/sap/piper/StepAssertions#11

This triggers an hudson.AbortException. This exception gets swallowed later in the surrounding exception handler vars/neoDeploy.groovy#142 when another excepetion gets raised by the failing catstatement inside the sh.

Next steps:

1.) Try to understand why the source cannot be found. Should be set earlier by mtaBuild. 2.) Rework the exception handler so that the original exception is not swallowed. 3.) Try to understand why there is no logs folder after mkdir -p

@citoki : In order to circumvent the issue we should provide the deployable via signature on neoDeploy: neoDeploy ./. source: for now and check if that resolves the issue.

By the way: I tried to reproduce the issue here, but on my side the logs folder is present and neo gets called ...

marcusholl commented 5 years ago

@citoki

Can you please check what happens if you use the version provided in branch pr/doNotSwallowOriginalException in repo https://github.com/marcusholl/jenkins-library?

This will not solve the issue, but currently we catch an exception, try to provide the logs, receive another exception while doing this and forget the first one. This should be fixed with the version above.

citoki commented 5 years ago

@marcusholl With the new PR I could see an extended error in Jenkins console.

The error was:
***
hudson.AbortException: File my-very-own-build-artifact.mtar cannot be found.
***
marcusholl commented 5 years ago

yes, I already saw this. Providing additional commits now with branch troubleshoot/neoDeploy in fork marcusholl/jenkins-library in order to understand the issue.

marcusholl commented 5 years ago

It is an issue with stashing.

ls after unstash reviles there is no mtar file:

[INFO] Unstashed "[workspace-f423697c-87de-4a71-94d8-d12c38aa9b3a]".
[Pipeline] sh
+ pwd
/home/jenkins/workspace/ntain_pipeline_teched2018-sample
+ whoami
root
+ ls -la
total 368
drwxr-xr-x    5 1000     1000           320 Apr  2 10:40 .
drwxr-xr-x    4 1000     1000           100 Apr  2 10:40 ..
-rw-r--r--    1 1000     1000           325 Apr  2 10:37 .editorconfig
-rw-r--r--    1 1000     1000            12 Apr  2 10:37 .eslintignore
-rw-r--r--    1 1000     1000          2888 Apr  2 10:37 .eslintrc
-rw-r--r--    1 1000     1000         14691 Apr  2 10:37 .eslintrc.ext
-rw-r--r--    1 1000     1000           114 Apr  2 10:37 .npmrc
drwxr-xr-x    2 1000     1000            60 Apr  2 10:40 .pipeline
drwxr-xr-x    2 1000     1000            60 Apr  2 10:40 .vscode
-rwxr-xr-x    1 1000     1000           317 Apr  2 10:37 Gruntfile.js
-rwxr-xr-x    1 1000     1000          1633 Apr  2 10:37 README.md
-rwxr-xr-x    1 1000     1000          3372 Apr  2 10:37 add-pp-xmake-props.sh
-rw-r--r--    1 1000     1000           653 Apr  2 10:37 mta.yaml
-rw-r--r--    1 1000     1000        323500 Apr  2 10:37 package-lock.json
-rwxr-xr-x    1 1000     1000          1487 Apr  2 10:37 package.json
drwxr-xr-x    8 1000     1000           220 Apr  2 10:40 webapp
marcusholl commented 5 years ago

Fixed with #632 in SAP/jenkins-Library. Please switch back to master branch and come back if it does not work. Otherwise close this issue, please.