Search code examples
concourse

How do I unlock a concourse pool resource?


We are trying to use a concourse pool to get locking. It locks just fine but when we try to release the lock, we are getting this error error releasing lock: open /tmp/build/put/maleficent-env/name: no such file or directory.

This is what the directory tree in our pool repo looks like

.
├── README.md
└── maleficent
    ├── claimed
    │   └── maleficent-env
    └── unclaimed

this is our resource:

 - name: 1.12-env
   type: pool
   source:
     uri: git@github.com:<repo>
     branch: master
     pool: maleficent
     private_key: {{key}}

this acquires the lock:

- put: 1.12-env params: {acquire: true}

and this is the job yml we think should release it:

- name: run-1.12-errand
plan:
- aggregate:
  - get: 1.12-env
    passed: [the-job-that-got-the-lock]
  - get: ci
  on_failure:
    put: 1.12-env
    params: {release: maleficent-env}
- task: run-errand
  file: ci/run-errand/task.yml
  params:
    BOSH_DIRECTOR_URL: {{url}}
    BOSH_CLIENT_SECRET: {{secret}}
    ENV_NAME: maleficent
  ensure:
    put: 1.12-env
    params: {release: maleficent-env}

One thing we noticed was when we did the get for the resource, it seems to be Cloning into '/tmp/build/get'… which is a different directory from where the unlocking step is looking for the file. What are we doing wrong?


Solution

  • The following job.yml will release your environment successfully

    - name: run-1.12-errand
      plan:
      - aggregate:
        - get: 1.12-env
          passed: [the-job-that-got-the-lock]
        - get: ci
        on_failure:
          put: 1.12-env
          params: {release: 1.12-env}
      - task: run-errand
        file: ci/run-errand/task.yml
        params:
          BOSH_DIRECTOR_URL: {{url}}
          BOSH_CLIENT_SECRET: {{secret}}
          ENV_NAME: maleficent
        ensure:
          put: 1.12-env
          params: {release: 1.12-env}
    

    The relevant line

    put: 1.12-env
    params: {release: 1.12-env}
    

    actually refers to two separate things, despite being both using 1.12-env. The put: 1.12-env means "Do a put of the resource named 1.12-env", while the release: 1.12-env means "Release the environment in the file that was the output of the get: 1.12-env"

    This is hopefully clearer in the following example

    - name: run-1.12-errand
      plan:
      - aggregate:
        - get: my-environment
          resource: 1.12-env
          passed: [the-job-that-got-the-lock]
        - get: ci
        on_failure:
          put: 1.12-env
          params: {release: my-environment}
      - task: run-errand
        file: ci/run-errand/task.yml
        params:
          BOSH_DIRECTOR_URL: {{url}}
          BOSH_CLIENT_SECRET: {{secret}}
          ENV_NAME: maleficent
        ensure:
          put: 1.12-env
          params: {release: my-environment}