Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Add support of concourse build environment in the base_url
Browse files Browse the repository at this point in the history
This commit add the support of build environment from concourse http://concourse.ci/implementing-resources.html#resource-metadata

Using the same function as context.
This will allow to generage your own base_url based on concourse build environment :

```
base_url: foo.com/$BUILD_JOB_NAME
```
  • Loading branch information
gaelL committed Apr 23, 2018
1 parent a18b3a9 commit 710373f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -41,6 +41,9 @@ resource_types:
linking to builds. On newer versions of Concourse ( >= v0.71.0) , the resource will
automatically sets the URL.

This supports the [build environment](http://concourse.ci/implementing-resources.html#resource-metadata)
variables provided by concourse. For example, `context: $BUILD_JOB_NAME` will set the context to the job name.

* `private_key`: *Optional.* Private key to use when pulling/pushing.
Example:
```
Expand Down
2 changes: 1 addition & 1 deletion assets/lib/commands/out.rb
Expand Up @@ -52,7 +52,7 @@ def output
contextes.each do |context|
Status.new(
state: params.status,
atc_url: atc_url,
atc_url: whitelist(context: atc_url),
sha: sha,
repo: repo,
context: whitelist(context: context)
Expand Down
11 changes: 11 additions & 0 deletions spec/commands/out_spec.rb
Expand Up @@ -39,6 +39,7 @@ def stub_status_post

stub_json(:get, "https://api.github.com:443/repos/jtarchie/test/statuses/#{@sha}", [])
ENV['BUILD_ID'] = '1234'
ENV['ATC_EXTERNAL_URL'] = 'default-test-atc-url.com'
end

def stub_json(method, uri, body)
Expand Down Expand Up @@ -236,6 +237,16 @@ def stub_json(method, uri, body)
end
end

context 'with base_url defined on source containing environment variable' do
it 'sets the target_url for status' do
ENV['BUILD_TEAM_NAME'] = 'build-env-var'
stub_status_post.with(body: hash_including('target_url' => 'http://example.com/build-env-var/builds/1234'))

put('params' => { 'status' => 'success', 'path' => 'resource' }, 'source' => { 'repo' => 'jtarchie/test', 'base_url' => 'http://example.com/$BUILD_TEAM_NAME' })
ENV['BUILD_TEAM_NAME'] = nil
end
end

context 'with no base_url defined, but with ATC_EXTERNAL_URL defined' do
it 'sets the target_url for status' do
ENV['ATC_EXTERNAL_URL'] = 'http://atc-endpoint.com'
Expand Down

0 comments on commit 710373f

Please sign in to comment.