Skip to content

Commit

Permalink
Merge pull request #14 from Taucher2003/13-add-support-for-variables
Browse files Browse the repository at this point in the history
Add support for passing variables to the GitLab pipeline
  • Loading branch information
Taucher2003 authored Nov 18, 2023
2 parents 25343e1 + 070a5a6 commit 2dfb509
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion lib/action/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module GitlabPipelineAction
class Context
attr_accessor :gh_project, :gh_sha, :gh_ref, :gh_server_url,
:gl_server_url, :gl_project_id, :gl_project_path, :gl_runner_token,
:gl_api_token, :gl_pipeline, :gl_branch_name,
:gl_api_token, :gl_pipeline, :gl_branch_name, :gl_pipeline_variables,
:git_repository, :git_path,
:gitlab_client,
:docker_runner_container
Expand Down
2 changes: 2 additions & 0 deletions lib/action/step/prepare_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def execute
context.gl_project_id = ENV.fetch('INPUT_GL_PROJECT_ID', nil)
context.gl_runner_token = ENV.fetch('INPUT_GL_RUNNER_TOKEN', nil)
context.gl_api_token = ENV.fetch('INPUT_GL_API_TOKEN', nil)
context.gl_pipeline_variables = ENV.select { |key| key.start_with?('GLPA_') }
.transform_keys { |key| key.delete_prefix('GLPA_') }

context.git_path = "/tmp/repo/#{SecureRandom.hex}"

Expand Down
3 changes: 2 additions & 1 deletion lib/action/step/trigger_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ 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,
context.gl_pipeline_variables
)

puts "Triggered: #{context.gl_pipeline.web_url}"
Expand Down
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 2dfb509

Please sign in to comment.