Skip to content

Commit

Permalink
Add support for passing variables to the GitLab pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Taucher2003 committed Nov 18, 2023
1 parent 25343e1 commit d8de62a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
GL_PROJECT_ID: '1000'
GL_RUNNER_TOKEN: some_long_runner_token
GL_API_TOKEN: TEST1234567890123456
env:
GLPA_SOME_VARIABLE: some value for the variable
- run: 'curl --silent --header "Private-Token: TEST1234567890123456" "http://127.17.0.1:8080/api/v4/projects/1000/jobs/1/trace"'
if: always()
- run: docker compose down
Expand Down
7 changes: 6 additions & 1 deletion lib/action/step/trigger_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ class TriggerPipeline < Base
def execute
context.gl_pipeline = context.gitlab_client.create_pipeline(
context.gl_project_id,
context.gl_branch_name
context.gl_branch_name,
variables
)

puts "Triggered: #{context.gl_pipeline.web_url}"
end

def variables
ENV.select { |key| key.start_with?('GLPA_') }.map { |key, value| [key.delete_prefix('GLPA_'), value] }.to_h
end
end
end
end
1 change: 1 addition & 0 deletions test/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
job:
script:
- echo $CI_COMMIT_SHA
- echo $SOME_VARIABLE

0 comments on commit d8de62a

Please sign in to comment.