GH-200 - Author and manage workflows (25% of the exam) - Section 1.7
Manage caching and artifacts and pass data between jobs and steps using GITHUB_ENV, GITHUB_OUTPUT, artifacts and reusable workflow outputs.
Cache dependency directories with actions/cache and upload and download build artifacts to share files across jobs. Pass step-level outputs via GITHUB_OUTPUT and job-level environment mutations via GITHUB_ENV.
actions/cacheartifactsGITHUB_OUTPUTGITHUB_ENV
Practice question for this objective
lock_openFree sampleAuthor and manage workflowsmedium
A reusable workflow called through workflow_call computes a build identifier and must return it to the caller so the caller can reference it as needs.call-build.outputs.build_id. The reusable file already sets a job output. What else must the reusable workflow declare for the value to reach the caller?
on:
workflow_call:
outputs:
build_id:
value: ${{ jobs.compute.outputs.build_id }}
ADeclare an output under on.workflow_call.outputs whose value maps to the job output, because a reusable workflow only returns values that are mapped through its workflow_call outputs block.check_circle Correct
BNothing further, because once a job inside the reusable workflow sets a job output, the caller can read it directly as needs.call-build.outputs.build_id without any on.workflow_call declaration.
CUpload the build identifier as an artifact in the reusable workflow, because the caller automatically downloads artifacts produced by a called workflow and reads them as job outputs.
DWrite the build identifier to the GITHUB_ENV file in the reusable workflow, because env values set there are inherited by the calling workflow and exposed under the called job's outputs.
Return data from a reusable workflow by mapping a job output through an on.workflow_call.outputs entry so the caller reads it via needs. A reusable workflow does not expose its internal job outputs automatically. It must declare each return value under on.workflow_call.outputs, setting that output's value to the relevant job output expression such as jobs.compute.outputs.build_id. Only then does the calling workflow read the value through the needs context of the job that called it. Artifacts and GITHUB_ENV do not bridge to the caller as outputs.
Why A is correct: A reusable workflow returns data only through an on.workflow_call.outputs entry whose value references the producing job output, so mapping build_id there lets the caller read needs.call-build.outputs.build_id.
Why B is wrong: Tempting because the job output exists, but a reusable workflow only exposes values the caller can read when they are declared under on.workflow_call.outputs, so the caller would otherwise see nothing.
Why C is wrong: Tempting because artifacts share data, but they are downloaded explicitly and are not surfaced as outputs, so an artifact cannot populate needs.call-build.outputs.build_id for the caller.
Why D is wrong: Tempting because GITHUB_ENV sets values, but those stay inside the job that wrote them and are never inherited by the caller, so they cannot become a reusable workflow output.
Answers that look right on this material and are not. Each one is a distractor from a different question in the GH-200 bank for this domain.
Append the pair to the GITHUB_ENV file, because values written there are later surfaced to expressions as step outputs under steps.meta.outputs.version.
errorWhy it is wrong: Tempting because GITHUB_ENV also receives key-value writes, but it sets environment variables read through the env context, not step outputs, so steps.meta.outputs.version stays empty.
if: needs.deps.outputs.cache-hit != 'true', because the cache result is published as a job output that later steps read through the needs context for the same run
errorWhy it is wrong: The needs context exposes outputs of upstream jobs, not steps within the current job, so this reference resolves to nothing and the gate fails to work as intended.
Append the assignment to the GITHUB_OUTPUT file, because values written there are promoted into the environment of every later step in the job.
errorWhy it is wrong: Tempting because GITHUB_OUTPUT also persists values, but it produces a step output read through the steps context, not an environment variable injected for later steps.