Skip to content

feat: Copy a failed build for a coding agent, with no AI provider needed - #264

Open
shenxianpeng wants to merge 1 commit into
mainfrom
feature/copy-for-agent
Open

shenxianpeng wants to merge 1 commit into
mainfrom
feature/copy-for-agent

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

Description

Coding agents such as Claude Code and Codex can fix what an explanation only describes: they work in a checkout of the repository, read the code and run the command that failed. What they lack is the failure, which is in Jenkins, often behind a login or on a network the agent cannot reach. Pasting a build link does not help there, and copying a raw console of thousands of lines is noisy and leaks secrets.

This adds Copy for AI agent to the console page of a failed build. It copies the failure written up for an agent:

  • the build, its result, and where its code came from: repository, branch and commit (from the Git plugin's variables, or else its record of the checkout), and the pull request of a multibranch build
  • the log of the steps that failed, read as the Explain Error button reads it (failing steps, parallel branches, global Max Log Lines and Log Pattern)
  • the explanation the build has, if any, marked as possibly wrong
  • what to do: reproduce with the command that failed, fix the cause, say how the fix was checked

Secrets are masked first, as for the provider. No AI provider is called, so the button works as soon as the plugin is installed, with no provider and no key, for anyone with Item/Read, and uses no quota. The global Enable AI Error Explanation and a folder's Turn off AI error explanation turn it off as well. The endpoint (console-explain-error/agentContext) is POST with the crumb; a GET gets 405. Where the browser does not let the page write to the clipboard (a Jenkins served over plain HTTP, or a refused permission), the text opens in a dialog with a Copy button.

The step header the extractor writes now names the stage (and parallel branch) and the command the step ran (sh script, error message; ten lines at most, without the Jenkinsfile's indentation). The agent needs it to reproduce the failure, and the AI explanation gets it too.

Before / After

Before After
No AI provider configured nothing on the console page Copy for AI agent
Provider configured Explain Error, Preview what is sent Explain Error, Copy for AI agent, Preview what is sent
What a coding agent gets from Jenkins a link it may not be able to open, or a raw console pasted by hand, secrets included the failing steps with stage and command, repository/branch/commit, the explanation, secrets masked

No provider configured, console page:

Before After
Desktop before after
Mobile before after

The text, in the dialog shown where the clipboard is not available:

Desktop Mobile
dialog dialog

Provider configured:

Before After
before after

End to end, on a local Jenkins with no provider: a Pipeline from a Git repository runs python3 -m unittest, and order_total() skips the first item (items[1:]). The copied text named the repository, branch main, the commit, stage Test, the command, both failing assertions, and masked the API_TOKEN echoed by the script (3 places). Pasted as is into Claude Code in a clone at that commit, it found items[1:], changed it to items, and ran the tests: 2 failures before, OK after.

Testing done

  • New AgentContextTest (10): a failed Pipeline without a provider (stage, command without indentation, log, masking, absolute build URL), repository/branch/commit from the Git plugin's checkout record and the pull request from the multibranch variables, the build's explanation, a log with backticks that cannot close its code block, permissions (Item/Read can, without it cannot, GET refused), explanation turned off (403, no button), the console page without a provider (only Copy for AI agent; the dialog with the text, as HtmlUnit has no clipboard), with a provider (both buttons in the console toolbar), indentation removal, branch names without their remote.
  • mvn verify (JDK 21): 1,068 tests, 0 failures after updating 4 assertions to the new behaviour (a reader now gets the agent button; the step header names the command, so the masked count rises from 2 to 4 and the log-pattern check looks at the log lines); SpotBugs 0 bugs.
  • Manual check on a local Jenkins 2.528.3, without and with a provider, desktop and phone width.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Was generative AI tooling used to co-author this PR?
  • Yes (please specify below)

The console page gets Copy for AI agent: the failure written up for
Claude Code, Codex or another coding agent, with the repository, branch,
commit and pull request, the log of the failing steps, the explanation
the build has, and what to do, secrets masked. No provider is called, so
it works as soon as the plugin is installed, for anyone who can read the
build. Where the clipboard is not available the text opens in a dialog.
Step headers now name the stage and the command the step ran.
@shenxianpeng shenxianpeng added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Oct 29, 2026
@shenxianpeng
shenxianpeng requested a review from a team as a code owner October 29, 2026 17:49
@shenxianpeng shenxianpeng added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant