Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should pipeline erros be displayed in pipeline's console? #357

Open
galindro opened this issue Mar 11, 2024 · 12 comments
Open

Should pipeline erros be displayed in pipeline's console? #357

galindro opened this issue Mar 11, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@galindro
Copy link

galindro commented Mar 11, 2024

Jenkins and plugins versions report

Environment
Jenkins version: 2.440.1
Pipeline Graph Plugin version: 230.vcd408a_1308dc

What Operating System are you using (both controller, and any agents involved in the problem)?

Linux RHEL8

Reproduction steps

Make a scripted pipeline with a withCredentials() pointing to a wrong credential ID, causing an error.

Expected Results

I would like to know if it is by desing that errors not related to any pipeline step / stage shouldn't be visible into the pipeline console, but only on the classical console.

Actual Results

Would be great if it could show such errors in the pipeline console, so we could deprecate the classical console. But I'm not sure if it is feasible and / or the intention of the pipeline console.

Anything else?

I would like to avoid situations like this. In this case, I had to point the user to the classical console....

image

image

Are you interested in contributing a fix?

No response

@galindro galindro added the bug Something isn't working label Mar 11, 2024
@timja
Copy link
Member

timja commented Mar 11, 2024

Can you provide an example pipeline?

If you have at least one stage I think it does something.
Yes something should be done if no stages. Similar to how blue ocean has a special view for a pipeline with no stage.

@galindro
Copy link
Author

galindro commented Mar 11, 2024

Well, my example is quite complex beucase I use a library that is capable to handle everything on my pipeline. However, it fails before execute the main library method, and that's what makes me believe that the pipeline console can't show any message that isn't within a proper stage or step.

It looks like this:

#!/usr/bin/env groovy

env.PIPELINE_VERSION = params.PIPELINE_VERSION ?: '1.0.0'
library "my-library@${PIPELINE_VERSION}"

// The error is triggered right here
withCredentials([string(credentialsId: 'my-fake-crendential', variable: 'token')]) {
  pipeline_args = [
      foo: [
          bar: [
              ['Foo', '.']
          ],
          test: [
              unit: [
                  foo: "./run_tests.sh",
                  bar: true,
              ],
          ],
      ]
  ]

  pipelines.my_pipeline(pipeline_args)
}

This is the console output that I get only on Classical Console:

Branch indexing
Checking out git ssh://[email protected]/myproject.git ssh://[email protected]/myproject.git into /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e to read Jenkinsfile
The recommended git tool is: NONE
using credential git-clone-ssh-key
using credential git-clone-ssh-key
 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e/.git # timeout=10
Fetching changes from 2 remote Git repositories
 > git config remote.origin.url ssh://[email protected]/myproject.git # timeout=10
Fetching without tags
Fetching upstream changes from ssh://[email protected]/myproject.git
 > git --version # timeout=10
 > git --version # 'git version 2.39.3'
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e@tmp/jenkins-gitclient-ssh1818745262322153566.key
Verifying host key using manually-configured host key entries
 > git fetch --no-tags --force --progress -- ssh://[email protected]/myproject.git +refs/pull-requests/7/from:refs/remotes/origin/PR-7 # timeout=10
 > git config remote.upstream.url ssh://[email protected]/myproject.git # timeout=10
Fetching without tags
Fetching upstream changes from ssh://[email protected]/myproject.git
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e@tmp/jenkins-gitclient-ssh18070165370414571004.key
Verifying host key using manually-configured host key entries
 > git fetch --no-tags --force --progress -- ssh://[email protected]/myproject.git +refs/heads/master:refs/remotes/upstream/master # timeout=10
Merging remotes/upstream/master commit 41ddebae4a51e475d2a91b63d70a62c8c42cd8e4 into PR head commit 63aed35633ad8b13415cd81c98095bb5e254535a
Enabling Git LFS pull
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 63aed35633ad8b13415cd81c98095bb5e254535a # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e@tmp/jenkins-gitclient-ssh3207120711477976840.key
Verifying host key using manually-configured host key entries
 > git lfs pull origin # timeout=10
 > git remote # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e@tmp/jenkins-gitclient-ssh12076950859987845500.key
Verifying host key using manually-configured host key entries
 > git merge 41ddebae4a51e475d2a91b63d70a62c8c42cd8e4 # timeout=10
 > git rev-parse HEAD^{commit} # timeout=10
Merge succeeded, producing 63aed35633ad8b13415cd81c98095bb5e254535a
Checking out Revision 63aed35633ad8b13415cd81c98095bb5e254535a (PR-7)
Enabling Git LFS pull
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 63aed35633ad8b13415cd81c98095bb5e254535a # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@script/9d087c2dc96479504d36a0f0d60a18bb5e2761c5ccc9a7ad91b6124dfd63865e@tmp/jenkins-gitclient-ssh4828728506188661202.key
Verifying host key using manually-configured host key entries
 > git lfs pull origin # timeout=10
Commit message: "some cleanup"
 > git rev-list --no-walk e298f79dfb15e8c331d0b63ca31cd31bcc435cb5 # timeout=10
[Bitbucket] Notifying pull request build result
[Pipeline] Start of Pipeline
[Pipeline] library
Loading library [email protected]
Attempting to resolve 4.0 from remote references...
 > git --version # timeout=10
 > git --version # 'git version 2.39.3'
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /tmp/jenkins-gitclient-ssh6541512564338258268.key
Verifying host key using manually-configured host key entries
 > git ls-remote -h -t -- [email protected]:my-library.git # timeout=10
Found match: refs/tags/1.0.0 revision dfbd96b7fddad5988ae5c520c8230bd3a7b834cd
Resolving tag commit... (remote references may be a lightweight tag or an annotated tag)
 > git rev-parse --resolve-git-dir /var/jenkins_home/caches/git-6ca32545813834634fae35af5b1fe5b0/.git # timeout=10
Setting origin to [email protected]:my-library.git
 > git config remote.origin.url [email protected]:my-library.git # timeout=10
Fetching origin...
Fetching upstream changes from origin
 > git --version # timeout=10
 > git --version # 'git version 2.39.3'
 > git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/caches/git-6ca32545813834634fae35af5b1fe5b0@tmp/jenkins-gitclient-ssh18116930509290609733.key
Verifying host key using manually-configured host key entries
 > git fetch --tags --force --progress -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/tags/1.0.0^{commit} # timeout=10
Resolved tag 4.0 revision dfbd96b7fddad5988ae5c520c8230bd3a7b834cd
The recommended git tool is: git
using credential git-clone-ssh-key
 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/myproject_PR-7@libs/8ce3be9b33354de99a0cae6b15ea11f4944a0b0706cbb451ecc7bafc62bb6066/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url [email protected]:my-library.git # timeout=10
Fetching with tags
Fetching upstream changes from [email protected]:my-library.git
 > git --version # timeout=10
 > git --version # 'git version 2.39.3'
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@libs/8ce3be9b33354de99a0cae6b15ea11f4944a0b0706cbb451ecc7bafc62bb6066@tmp/jenkins-gitclient-ssh16595787106457685866.key
Verifying host key using manually-configured host key entries
 > git fetch --tags --force --progress -- [email protected]:my-library.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision dfbd96b7fddad5988ae5c520c8230bd3a7b834cd (4.0)
Enabling Git LFS pull
 > git config core.sparsecheckout # timeout=10
 > git checkout -f dfbd96b7fddad5988ae5c520c8230bd3a7b834cd # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials SSH Key
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/myproject_PR-7@libs/8ce3be9b33354de99a0cae6b15ea11f4944a0b0706cbb451ecc7bafc62bb6066@tmp/jenkins-gitclient-ssh5030342436657586019.key
Verifying host key using manually-configured host key entries
 > git lfs pull origin # timeout=10
Commit message: "Merge pull request #30"
 > git rev-list --no-walk dfbd96b7fddad5988ae5c520c8230bd3a7b834cd # timeout=10
[Pipeline] withCredentials
[Pipeline] // withCredentials
[Pipeline] End of Pipeline
ERROR: Could not find credentials entry with ID 'my-fake-crendential'
[Bitbucket] Notifying pull request build result
[Bitbucket] Build result notified
Finished: FAILURE

@timja
Copy link
Member

timja commented Mar 11, 2024

thanks best way to add a reproducer is to just create a simple pipeline that does the same thing.

Likely this is enough:

withCredentials([string(credentialsId: 'my-fake-crendential', variable: 'token')]) {
 echo 'test'
}

@galindro
Copy link
Author

@timja, do you have time to work on this fix?

@timja
Copy link
Member

timja commented Mar 12, 2024

Most likely at some point unless someone else gets to it first, but no timescales right now.

@timbrown5
Copy link
Contributor

Are you able to check if this works with version 227 (or any before 230)?

makes me believe that the pipeline console can't show any message that isn't within a proper stage or step.
This is sort of true - all errors need to be inside a FlowNode (a Pipeline graph object) to be supported. A simple example of this is a syntax error - if the Pipeline graph doesn't compile we will struggle to show any information - as we parse the resulting DAG.
This will show similar behaviour to what you're seeing:
pipeline {

That said, if the Pipeline has compiled and started in any way, we should get a Start and Stop node which should capture the error - there is a test that checks for a that just calls an invalid function, and it's working locally for me:
Screenshot from 2024-03-12 10-07-56
(I realise now that the file is named incorrectly pipelineWithSyntaxError.jenkinsfile as the example code doesn't have a syntax error).

Your example log lists [Pipeline] Start of Pipeline so I think it should be supportable.

There might also be an option of adding a fake node on things like syntax error which can then house the exception message.

@galindro
Copy link
Author

The same behavior occurs on version 227 @timbrown5:

image

image

image

image

@timja
Copy link
Member

timja commented Mar 12, 2024

I can reproduce it with just #357 (comment)

@timja
Copy link
Member

timja commented Mar 12, 2024

The code goes into here:

if (errorAction != null && !PipelineNodeUtil.isJenkinsFailureException(errorAction.getError())) {

Finds the ErrorAction
Doesn't go into the if block because PipelineNodeUtil.isJenkinsFailureException(errorAction.getError()) returns true and it's inverted with !PipelineNodeUtil.isJenkinsFailureException(errorAction.getError())

The

if (node instanceof BlockEndNode<?> && nodeMap.values().size() <= 2) {

node is an instanceof BlockEndNode but there's 4 nodes so it doesn't go into that block.

I think maybe we just need some generic handling for when there's no stages and this would work.

@timja
Copy link
Member

timja commented Mar 12, 2024

This #363 fixes this specific case, I'd like to explore some more cases as well.

It unfortunately does it with a synthetic node even though a step is available, I might see if I can fix that

@timja
Copy link
Member

timja commented Mar 12, 2024

It seems like block steps with errors are just not handled.
Even blue ocean handles it poorly (it inserts the log text into the last step above it without creating a node for it.

example pipeline where the step doesn't show up at all:

stage('withCredentials') {
    echo "Yo"
    withCredentials([string(credentialsId: 'my-fake-crendential', variable: 'token')]) {
     echo 'test'
    }

}

Because it's a block step it gets filtered out of the map and because its a blockendnode that has the exception on the node its just not really considered.

@timbrown5
Copy link
Contributor

My long term goal was to return StepBlocks as well - how to handle them in the front end is a question.

In the short term, we could move Exceptions from StepBlocks to their parent Block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants