CleanupArtifacts
The CleanupArtifacts job template deletes pipeline artifacts that were only needed to hand data from one job to
the next.
Artifacts are not addressed by their literal names, but by keys into the JSON dictionary of artifact names produced by Parameters. A pipeline therefore never repeats an artifact name, and renaming an artifact in one place does not silently leave a stale one behind.
Two independent sets of artifacts can be deleted, each guarded by its own condition. That is how CompletePipeline deletes the intermediate reports on every run, but the package artifact only when it is not a release run - on a release run PublishOnPyPI consumes and deletes it.
Note
CleanupArtifacts replaces the deprecated ArtifactCleanUp and IntermediateCleanUp
templates.
Artifact ID Syntax
artifact-json-ids takes a space or newline separated list of entries. Each
entry is resolved against the JSON dictionary given by json. The list of entries in
artifact-json-ids2 is looked up in json2:
Entry |
Resolves to |
|---|---|
|
the artifact name stored under |
|
the artifact name followed by |
|
|
|
|
|
ignored - used to comment out an entry |
Hint
Assume a matrix creating multiple artifacts sharing the same prefix. That prefix is taken from the JSON dictionary,
e.g. artifactNames['unittesting_xml'] (= 'myProject-UnitTestReportSummary-XML'). Each matrix job then adds a
postfix specific to its matrix combination like operating system, platform details or Python version (=
'-ubuntu-3.14').
The resulting artifact name is myProject-UnitTestReportSummary-XML-ubuntu-3.14.
To delete all these variants, unittesting_xml:-* can be used.
The merged unit test XML artifact is not deleted by this entry, because that one uses
artifactNames['unittesting_xml'] directly, without a postfix. Deleting it too needs a second entry
unittesting_xml - which is why both forms appear in the example below.
artifact-json-ids: >-
unittesting_xml:-*
unittesting_xml
statictyping_html
#documentation_latex
A key that is not present in the dictionary is reported and skipped.
Instantiation
The following instantiation example creates an ArtifactCleanUp job derived from job template
CleanupArtifacts version @r8. It deletes the report artifacts on every run, and the package artifact only when
the pipeline is not a tagged release.
jobs:
ArtifactCleanUp:
uses: pyTooling/Actions/.github/workflows/CleanupArtifacts.yml@r8
needs:
- Prepare
- Params
- UnitTesting
- Documentation
if: ${{ !cancelled() }}
with:
json: ${{ needs.Params.outputs.artifact_names }}
artifact-json-ids: >-
unittesting_xml:-*
codecoverage_sqlite:-*
unittesting_xml
codecoverage_html
documentation_html
json2: ${{ needs.Params.outputs.artifact_names }}
condition2: ${{ needs.Prepare.outputs.is_release_tag != 'true' }}
artifact-json-ids2: >-
package_all
Attention
The job should be given an if: expression containing a status check function, such as !cancelled(). If no
such function is present, the cleanup is skipped as soon as a single upstream job was skipped, and the artifacts
are kept until their retention period expires.
See also
- IntermediateCleanUp
Deprecated. Deleted the per-matrix-job artifacts in the middle of a pipeline; this template does the same job with a
jsondictionary instead of two hard-coded prefixes.- ArtifactCleanUp
Deprecated predecessor of this template.
- Conditional Jobs
Why an
if:without a status check function skips the cleanup.
Parameter Summary
Goto input parameters
Parameter Name |
Required |
Type |
Default |
|---|---|---|---|
no |
string |
|
|
no |
string |
|
|
no |
boolean |
|
|
no |
string |
|
|
no |
string |
|
|
no |
boolean |
|
|
no |
string |
|
|
no |
string |
|
Goto secrets
This job template needs no secrets.
Goto output parameters
This job template has no output parameters.
Input Parameters
ubuntu_image_version
- Type:
string
- Required:
no
- Default Value:
'26.04'- Possible Values:
See actions/runner-images - Available Images for available Ubuntu image versions.
- Description:
Version of the Ubuntu image used to run the job.
Note
Unfortunately, GitHub Actions has only a limited set of functions, thus, the usual Ubuntu image name like
'ubuntu-26.04'can’t be split into image name and image version.
json
- Type:
string (JSON)
- Required:
no
- Default Value:
'{}'- Possible Values:
Any valid JSON string containing a JSON object mapping keys to artifact names.
- Description:
Dictionary of artifact names the first set of IDs is resolved against.
Usually taken from artifact_names.
condition
- Type:
boolean
- Required:
no
- Default Value:
true- Possible Values:
true/false- Description:
Guard for the first set of artifacts.
true- delete the artifacts computed from artifact-json-ids.
false- keep them.
artifact-json-ids
- Type:
string
- Required:
no
- Default Value:
''- Possible Values:
A space or newline separated list of entries - see Artifact ID Syntax.
- Description:
Keys of the first set of artifacts to be deleted.
json2
- Type:
string (JSON)
- Required:
no
- Default Value:
'{}'- Possible Values:
Any valid JSON string containing a JSON object mapping keys to artifact names.
- Description:
Dictionary of artifact names the second set of IDs is resolved against.
Usually the same dictionary as json; the second set exists for its separate condition, not for a different dictionary.
condition2
- Type:
boolean
- Required:
no
- Default Value:
true- Possible Values:
true/false- Description:
Guard for the second set of artifacts.
true- delete the artifacts computed from artifact-json-ids2.
false- keep them.
artifact-json-ids2
- Type:
string
- Required:
no
- Default Value:
''- Possible Values:
A space or newline separated list of entries - see Artifact ID Syntax.
- Description:
Keys of the second set of artifacts to be deleted.
others
- Type:
string
- Required:
no
- Default Value:
''- Possible Values:
A newline separated list of artifact names. Glob patterns are supported.
- Description:
Further artifacts to be deleted by literal name, for artifacts that are not part of an artifact-name dictionary.
Secrets
This job template needs no secrets.
Outputs
This job template has no output parameters.