Skip to content

Job

The Job class represents a single job within a GitHub Actions workflow. Jobs can either run steps directly or call reusable workflows.

from ghagen import Job, Step
job = Job(
name="Test",
runs_on="ubuntu-latest",
steps=[
Step(uses="actions/checkout@v4"),
Step(name="Run tests", run="pytest"),
],
)
ParameterTypeDefaultDescription
namestr | NoneNoneDisplay name for the job.
runs_onstr | list[str] | Raw[str] | NoneNoneRunner label(s) for this job (e.g., "ubuntu-latest"). Serialized as runs-on.
needsstr | list[str] | NoneNoneJob ID(s) that must complete before this job runs.
if_str | NoneNoneConditional expression that must evaluate to true for this job to run. Serialized as if.
permissionsPermissions | NoneNoneToken permissions for this job. See Permissions.
environmentstr | Environment | NoneNoneDeployment environment. Can be a string (name only) or an Environment object.
strategyStrategy | NoneNoneMatrix strategy configuration. See Strategy.
envdict[str, str] | NoneNoneEnvironment variables for all steps in this job.
defaultsDefaults | NoneNoneDefault settings for run steps. See Workflow - Defaults.
stepslist[Step] | NoneNoneSteps to run. See Step.
outputsdict[str, str | JobOutput] | NoneNoneJob outputs, accessible by downstream jobs. Values can be strings or JobOutput objects.
timeout_minutesint | NoneNoneMaximum minutes the job can run before being cancelled. Serialized as timeout-minutes.
continue_on_errorbool | str | NoneNoneAllow the workflow to continue when this job fails. Serialized as continue-on-error.
concurrencystr | Concurrency | NoneNoneConcurrency group for this job. See Workflow - Concurrency.
servicesdict[str, Service | str] | NoneNoneService containers for the job. Values can be Service objects or image strings.
containerContainer | str | NoneNoneContainer to run the job in. Can be a Container object or an image string.

These fields are used when calling a reusable workflow instead of running steps directly.

ParameterTypeDefaultDescription
usesstr | NoneNoneReusable workflow reference (e.g., "org/repo/.github/workflows/ci.yml@main").
with_dict[str, Any] | NoneNoneInput parameters for the reusable workflow. Serialized as with.
secretsdict[str, str] | str | NoneNoneSecrets to pass. Can be a dict or "inherit".

Job strategy configuration including matrix builds, fail-fast behavior, and parallelism limits.

ParameterTypeDefaultDescription
matrixMatrix | NoneNoneMatrix configuration. See Matrix.
fail_fastbool | NoneNoneWhether to cancel all in-progress jobs if any matrix job fails. Serialized as fail-fast.
max_parallelint | NoneNoneMaximum number of matrix jobs to run in parallel. Serialized as max-parallel.

Strategy matrix configuration. Dynamic dimensions are set via the extras parameter since they are user-defined keys.

from ghagen.models.job import Matrix, Strategy
strategy = Strategy(
matrix=Matrix(
extras={
"python-version": ["3.11", "3.12", "3.13"],
"os": ["ubuntu-latest", "macos-latest"],
},
include=[{"os": "ubuntu-latest", "experimental": True}],
exclude=[{"os": "macos-latest", "python-version": "3.11"}],
),
)
ParameterTypeDefaultDescription
includelist[dict[str, Any]] | NoneNoneAdditional matrix combinations to include.
excludelist[dict[str, Any]] | NoneNoneMatrix combinations to exclude.
extrasdict[str, Any]{}Dynamic matrix dimensions (e.g., {"python-version": ["3.11", "3.12"]}). These are user-defined keys emitted at the top level of the matrix. Inherited from base model.

Job environment configuration for deployment environments.

ParameterTypeDefaultDescription
namestrrequiredThe environment name.
urlstr | NoneNoneThe environment URL.

A job output definition, used when a downstream job needs to consume this job’s outputs.

ParameterTypeDefaultDescription
descriptionstr | NoneNoneDescription of the output.
valuestrrequiredThe output value, typically a step output expression.

Container configuration for running a job inside a Docker container.

from ghagen.models.container import Container
container = Container(
image="node:20",
env={"CI": "true"},
ports=["8080:80"],
)
ParameterTypeDefaultDescription
imagestrrequiredDocker image to use.
credentialsdict[str, str] | NoneNoneRegistry credentials (username and password).
envdict[str, str] | NoneNoneEnvironment variables for the container.
portslist[str | int] | NoneNonePorts to expose on the container.
volumeslist[str] | NoneNoneVolumes to mount.
optionsstr | NoneNoneAdditional docker create options.

Service container configuration. Has the same shape as Container and is used for sidecar services (databases, caches, etc.) that run alongside a job.

ParameterTypeDefaultDescription
imagestrrequiredDocker image to use.
credentialsdict[str, str] | NoneNoneRegistry credentials.
envdict[str, str] | NoneNoneEnvironment variables for the service.
portslist[str | int] | NoneNonePorts to expose.
volumeslist[str] | NoneNoneVolumes to mount.
optionsstr | NoneNoneAdditional docker create options.