Implements a resource that passes to a task the metadata of the job.
Caution: misuse may result in angry concourse developers. This resource was created for the sole purpose of linking the Artifactory artifacts to the current build.
Opinionated pipeline suggestion here
This resource was implemented based on the build-metadata-resource
resource_types:
- name: meta
type: docker-image
source:
repository: swce/metadata-resource
resources:
- name: meta
type: meta
None.
check
: Produce a single dummy keyProduce the current timestamp to invalidate the previous version so every build will get a fresh and relevant copy of the metadata.
in
: Write the metadata to the destination dirNone.
out
: UnusedUnused
None.
resource_types:
- name: meta
type: docker-image
source:
repository: swce/metadata-resource
resources:
- name: meta
type: meta
jobs:
- name: build
plan:
- get: meta
- task: build
file: tools/tasks/build/task.yml
The build job gets in the meta
dir all the files with the respected values in them to use as it pleases
Use this resource to link the artifacts created by the build step to the current build. This is helpfull in a couple of ways:
We will use the keyval-resource to pass the build number to the step that will release the artifact to production.
The pipeline.yml
file:
resource_types:
- name: meta
type: docker-image
source:
repository: swce/metadata-resource
- name: keyval
type: docker-image
source:
repository: swce/keyval-resource
resources:
- name: meta
type: meta
- name: keyval
type: keyval
jobs:
- name: build
plan:
- get: meta
- task: build
file: tools/tasks/build/task.yml
- put: keyval
params:
file: keyvalout/keyval.properties
...
- name: prod-deploy
plan:
- get: keyval
- task: prod-deploy
file: tools/tasks/prod-deploy/task.yml
The build
task:
pipeline_id=`cat "${ROOT_FOLDER}/meta/build-name"`
echo "Pipeline id is $pipeline_id"
export "PASSED_PIPELINE_ID=$pipeline_id"
...
gradlew ... -PbuildId="${PASSED_PIPELINE_ID}"
The build.gradle
file of the project:
artifactory {
publish {
publishBuildInfo = true
}
clientConfig.info.setBuildNumber(buildId)
clientConfig.publisher.addMatrixParam(BuildInfoFields.BUILD_NUMBER, buildId)
}
The prod-deploy
task:
...
echo "Promoting build to production repo"
local appName=$(retrieveAppName)
local args="{\"status\": \"Deployed\",\"comment\": \"moving to production\",\"copy\": true,\"sourceRepo\": \"${REPO_SNAPSHOT}\",\"targetRepo\": \"${REPO_RELEASE}\",\"properties\": {\"retention.pinned\":[\"7\"]}}"
curl --fail -u "${artifactory_user}:${artifactory_password}" -H "Content-Type: application/json" -X POST -d "'$args'" "${artifactory_contextUrl}/api/build/promote/${appName}/${PASSED_PIPELINE_ID}"
The tests have been embedded with the Dockerfile
; ensuring that the testing
environment is consistent across any docker
enabled platform. When the docker
image builds, the test are run inside the docker container, on failure they
will stop the build.
Run the tests with the following command:
docker build -t metadata-resource .
Please make all pull requests to the master
branch and ensure tests pass
locally.