Add V2 CI helpers and job logs #1173
Open
+1,919
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
=========
Internal Checklist
Changes
=======
circleci project id <project-slug>command to print project UUID.circleci pipeline listto accept<project-id|project-slug>(slug→project-id resolution).circleci pipeline definitions list <project-slug>convenience command.circleci pipeline runs latest <project-slug> --branch <branch> [--json].circleci pipeline workflows <pipeline-id> [--json].circleci workflow jobs <workflow-id> [--json].circleci job logs <project-slug> <job-number> [--step ...] [--json]to fetch step outputs (v1.1 job details + presigned output URLs).circleci job image-tag <project-slug> <job-number> [--step ...] [--regex ...]to extract image tag(s) from step output.K9S_CIRCLECI_CLI_TOKENis unavailable (e.g. forked PR CI).Rationale
=========
CircleCI CLI already supports v2 status discovery (pipelines/workflows/jobs) but does not expose job step logs or step outputs needed to debug build steps and to derive artifacts like image tags.
This PR adds first-class commands so users can stay within the CLI instead of stitching together multiple
curl/jqcalls.Considerations
==============
circleci job logs/circleci job image-tagrely on the v1.1 job details endpoint and its presignedoutput_urlfields.--stepsupports 1-based index, exact name, and substring matches to make it easy to target a specific step in a job.How to Test
============
Build and run tests:
make buildmake test(orgo test ./...)Set your token (either works):
Note: The
@k9sintegration scenario requiresK9S_CIRCLECI_CLI_TOKEN. If it is not set, the scenario is skipped.circleci setupexport CIRCLECI_CLI_TOKEN=...Choose a project/branch (example uses this repo):
PROJECT=gh/CircleCI-Public/circleci-cliBRANCH=mainProject ID:
circleci project id $PROJECTPipeline definitions (slug-based):
circleci pipeline definitions list $PROJECTcircleci pipeline list $PROJECTLatest pipeline run:
pipeline_id=$(circleci pipeline runs latest $PROJECT --branch $BRANCH | cut -f1)circleci pipeline runs latest $PROJECT --branch $BRANCH --json | jq -r '.id'Workflows for the pipeline:
workflow_id=$(circleci pipeline workflows $pipeline_id --json | jq -r '.[0].id')Jobs for the workflow:
circleci workflow jobs $workflow_idjob_number=$(circleci workflow jobs $workflow_id --json | jq -r '.[] | select(.name=="build") | .job_number' | head -n1)Job logs:
circleci job logs $PROJECT $job_number(full)circleci job logs $PROJECT $job_number --step "Checkout code"circleci job logs $PROJECT $job_number --json | jq -r '.steps[].name'Image tags:
circleci job image-tag $PROJECT $job_number(defaults to “Build Docker image”/“Push Docker images”)circleci job image-tag $PROJECT $job_number --step "<step name>"circleci job image-tag $PROJECT $job_number --step "<step name>" --regex '<your-regex-with-capture-group>'Screenshots
============
N/A (CLI output only)
Note
Introduces first-class CLI utilities for v2 pipelines/workflows and v1.1 job step logs.
jobcommands:job logs(fetch step outputs; optional--step,--json) andjob image-tag(extract tags via regex; defaults to common Docker steps)pipelineutilities:pipeline runs latest --branch,pipeline workflows <pipeline-id> [--json],pipeline definitions list <project-slug>, and enhancedpipeline listto accept<project-id|project-slug>workflow jobs <workflow-id> [--json]andproject id <project-slug>commandsslug.ParseProjecthelperK9S_CIRCLECI_CLI_TOKENis absentpull/*branchesWritten by Cursor Bugbot for commit 08a2023. This will update automatically on new commits. Configure here.