Implements a resource that passes key values between jobs without using any external resource such as git/s3 etc.
This resource was implemented based on the time resource
resource_types:
- name: keyval
type: docker-image
source:
repository: moredhel/keyval-resource
resources:
- name: keyval
type: keyval
None.
check: Produce a single dummy keyThis is a version-less resource so check behavior is no-op
in: Report the given time.Fetches the given key values and stores them in their own files where the key is the name of the file and the value is the contents.
version:
my_secret: secret_value
would result in:
$ cat resource/my_secret
secret_value
None.
out: Consumes the given properties fileNOT IMPLEMENTED (pull-requests welcome)
resource_types:
- name: keyval
type: docker-image
source:
repository: moredhel/keyval-resource
resources:
- name: keyval
type: keyval
jobs:
- name: build
plan:
- task: build
file: tools/tasks/build/task.yml
- put: keyval
params:
file: keyvalout/keyval.properties
- name: test-deploy
plan:
- aggregate:
- get: keyval
passed:
- build
- task: test-deploy
file: tools/tasks/task.yml
The build job writes all the key values it needs to pass along (e.g. artifact id) in the keyvalout/keyval.properties file.
The test-deploy can read the data from the keyval/keyval.properties file and use them as it pleases.
You can add the following bash script to the start of every job to auto export the passed key values, if they exist.
The script assumes that the resource folder is keyval.
#!/bin/bash
props="${ROOT_FOLDER}/keyval/keyval.properties"
if [ -f "$props" ]
then
echo "Reading passed key values"
while IFS= read -r var
do
if [ ! -z "$var" ]
then
echo "Adding: $var"
export "$var"
fi
done < "$props"
fi
You can add the following bash script to the end of every job to auto pass specific environment variables as key values to the next job.
The script only passes environment variables that start with PASSED_.
The script assumes that the resource out file is keyvalout/keyval.properties:
e.g.
- put: keyval
params:
file: keyvalout/keyval.properties
#!/bin/bash
propsDir="${ROOT_FOLDER}/keyvalout"
propsFile="${propsDir}/keyval.properties"
if [ -d "$propsDir" ]
then
touch "$propsFile"
echo "Setting key values for next job in ${propsFile}"
while IFS='=' read -r name value ; do
if [[ $name == 'PASSED_'* ]]; then
echo "Adding: ${name}=${value}"
echo "${name}=${value}" >> "$propsFile"
fi
done < <(env)
fi
NOTE: Tests have not yet been rewritten to reflect the updated configuration
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 keyval-resource .
Please make all pull requests to the master branch and ensure tests pass
locally.
Content type
Image
Digest
Size
9.8 MB
Last updated
over 6 years ago
Requires Docker Desktop 4.37.1 or later.