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

implement support of passing all exported vars to other commands #70

Merged
merged 2 commits into from
May 8, 2023

Conversation

umputun
Copy link
Owner

@umputun umputun commented May 8, 2023

This PR adds ability to export some variables in one command and get it from env of the another command. From user's point of view this should be expected behavior and it feels like all the commands run in the same shell script. However, internally command detects all the exports inside the script and append result of evaluation of those variables to the end of the executed script as echo setvar foo=bar

After the command executed those setvar extracted and set to all other commands as a regular env.

This snippet indicates the possible use-case:

      - name: some command
        script: |
          export foo=$((1 + 2 + 3))
          export bar=$((4 + 5))
          export baz=zzzzz
          ls -laR /tmp
          du -hcs /srv
          cat /tmp/conf.yml
          echo all good, 123

      - name: user variables
        script: |
          env
          echo "var foo: ${foo}"
          echo "var bar: ${bar}"
          echo "var baz: ${baz}"
        env: {baz: qux}

In this example the first command export foo, bar and baz variables. foo and bar are evaluated, but baz is not because it set directly by env. It is not clear to me if this override should be allowed, but i feel it could be a source for confusion, so for now it will keep the original (qux) value

The next command, i.e. "user variables" will get all those vars and will print

var foo: 6
var bar: 9
var baz: qux

@coveralls
Copy link

coveralls commented May 8, 2023

Pull Request Test Coverage Report for Build 4918902321

  • 59 of 70 (84.29%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.3%) to 84.215%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/runner/runner.go 42 53 79.25%
Files with Coverage Reduction New Missed Lines %
pkg/runner/runner.go 1 84.53%
Totals Coverage Status
Change from base Build 4917857771: 0.3%
Covered Lines: 1798
Relevant Lines: 2135

💛 - Coveralls

@umputun
Copy link
Owner Author

umputun commented May 8, 2023

implements #69

@umputun umputun merged commit f344098 into master May 8, 2023
3 checks passed
@umputun umputun deleted the custom_vars branch May 8, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants