Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Use vars in runners.endpoint #932

Closed
souchan2000 opened this issue May 21, 2024 · 3 comments
Closed

Unable to Use vars in runners.endpoint #932

souchan2000 opened this issue May 21, 2024 · 3 comments
Labels
question Further information is requested

Comments

@souchan2000
Copy link

I've run into an issue when trying to use vars in the endpoint of runners in the following script:
env/local.json

{
  "endpoint": "http://localhost:3000/api"
}

env/production.json

{
  "endpoint": "https://example.com/api"
}

example.yml

desc: example
vars:
  env: 'json://env/${ENVIRONMENT}.json'
runners:
  service:
    endpoint: '{{ vars.env.endpoint }}'
steps:
  - dump: vars.env.endpoint
  - service:
      /users/me:
        get:
          test: current.res.status == 200

The results obtained from execution:

$ ENVIRONMENT=local runn run example.yml --debug

Run "dump" on "example".steps[0]
http://localhost:3000/api

Run "service" on "example".steps[1]
-----START HTTP REQUEST-----
GET %7B%7B%20vars.env.endpoint%20%7D%7D/users/me HTTP/1.1


-----END HTTP REQUEST-----
F

1) example.yml 7d163e60ed7a29276077adb17f2b6c37f8239391
  Failure/Error: http request failed on "example".steps[1]: Get "%7B%7B%20vars.env.endpoint%20%7D%7D/users/me": unsupported protocol scheme ""
  Failure step (example.yml):
   9   - service:
  10       /users/me:
  11         get:
  12           test: current.res.status == 200


1 scenario, 0 skipped, 1 failure

Specifically, using '{{ vars.env.endpoint }}' directly in the endpoint of runners.service doesn't seem to work as expected.

The expected behaviour is that vars.env.endpoint is correctly expanded in service.endpoint and it becomes possible to set the endpoint dynamically based on env.

If there is a solution to this problem, or an alternative way to dynamically set the endpoint using vars, I would appreciate your advice.

@k1LoW
Copy link
Owner

k1LoW commented May 21, 2024

Values in the vars: section cannot be used in the runners: section of the same runbook.

Variables can be used if they are in the runners: section of the runbook loaded by the include runner.

@k1LoW k1LoW added the question Further information is requested label May 21, 2024
@k1LoW
Copy link
Owner

k1LoW commented Jun 20, 2024

Hi @souchan2000.

From v0.113.1, runners can be defined in the middle of a step.

https://github.com/k1LoW/runn?tab=readme-ov-file#runner-runner-define-runner-in-the-middle-of-steps

@souchan2000
Copy link
Author

Sorry for the late reply, I'll try using the information you suggested. Thank you.

@k1LoW k1LoW closed this as completed Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants