Skip to content

Commit

Permalink
Merge pull request #3024 from zendesk/grosser/env2
Browse files Browse the repository at this point in the history
make env variables always be valid
  • Loading branch information
grosser authored Oct 29, 2018
2 parents a56d295 + cb440ed commit 2525d77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/job_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ def make_builds_available

# make repo-digests available to stage commands
builds.map do |build|
["BUILD_FROM_#{build.dockerfile || build.image_name}", build.docker_repo_digest]
name = build.dockerfile || build.image_name
name = name.gsub(/[^A-Za-z\d_]/, "_") # IEEE Std 1003.1-2001 A-Z, digits, '_' (+ a-z for backwards compatibility)
["BUILD_FROM_#{name}", build.docker_repo_digest]
end.to_h
end

Expand Down
6 changes: 6 additions & 0 deletions test/models/job_execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ def last_line_of_output
job.output.must_include "export BUILD_FROM_Dockerfile=docker-registry.example.com"
end

it "creates valid env variables when build name is not valid" do
build.update_columns(dockerfile: nil, image_name: 'foo-bar-∂-baz')
JobExecution.new('master', job).send(:run)
job.output.must_include "export BUILD_FROM_foo_bar___baz=docker-registry.example.com"
end

it "makes builds without dockerfile available via env" do
build.update_columns(dockerfile: nil, image_name: 'foo')
JobExecution.new('master', job).send(:run)
Expand Down

0 comments on commit 2525d77

Please sign in to comment.