Passing resources as params


#1

I’m trying to run a job, using a resource as a param. This is what I’m trying to do:

resources:
- name: myrepo
  type: git
  source:
  uri: https://github.com/myorg/myrepo.git

jobs:
    - name: do-something
      plan:
        - get: myrepo
        - task: do-something
          config:
            platform: linux
            image_resource:
              type: docker-image
              source: {repository: cloudposse/github-status-updater}
            params:
              GIT_REF: ((myrepo/.git/short_ref))

However, GIT_REF is passed literally, instead of using a value from the resource.

The best option I’ve been able to come up with is running a custom command to set the envvar, then calling into the image’s entrypoint:

config:
  platform: linux
  image_resource:
    type: docker-image
    source: {repository: cloudposse/github-status-updater}
  run:
    path: sh
    args:
      - -c
      - |
        export GIT_REF=$(cat myrepo/.git/short_ref)
        github-status-updater

This works, but is less than ideal, as it breaks the container abstraction, requiring us to update this script if the name of the binary in the github-status-updater image changes.

Is there something I’m missing in the documentation, or is a mechanism like this not currently possible?


#3

The way I would do it is I would define the task to have an input, let’s say “project”, and I would pass resource as input, like this:

resources:
- name: myrepo
  type: git
  source:
  uri: https://github.com/myorg/myrepo.git

jobs:
    - name: do-something
      plan:
        - get: myrepo
        - task: do-something
          config:
            platform: linux
            image_resource:
              type: docker-image
              source: {repository: cloudposse/github-status-updater}
            inputs:
            - name: myrepo
            run:
              path: /path/to/update-script.sh

the update-script.sh would have access to myrepo directory in the current working folder.