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

Can withPythonEnv block also affect sh steps? #6

Closed
r4v5 opened this issue Oct 30, 2017 · 5 comments
Closed

Can withPythonEnv block also affect sh steps? #6

r4v5 opened this issue Oct 30, 2017 · 5 comments

Comments

@r4v5
Copy link

r4v5 commented Oct 30, 2017

This plugin is useful, but multiple people in my organization, when trying it, have missed the fact that any commands you want to run within a virtualenv must be invoked as pysh steps instead of regular sh.
The typical behavior we've come to expect for withSomething{} pipeline blocks (withEnv, withCredentials, etc) has been that they affect the behavior of every shell command within the block; is there a reason (technical or philosophical) for separating out that behavior in this plugin?

@cstarner
Copy link

Plugging into the sh and bat steps had been my original goal when I was first working on this plugin; however I didn't find a way to accomplish this. I attempted to intercept the sh and bat commands in order to conditionally manipulate them; however, it appears that Jenkins doesn't allow this kind of behavior (with good reason, it could potentially lead to very difficult to trace issues).

Since virtualenv works primarily through the manipulation of environmental variables, it is theoretically possible to supply the manipulated environment to each sh command that occurs within the block; however, I didn't see a good way to accomplish this either, short of reimplementing virtualenv myself.

This is why I made the decision to use pysh and pybat instead.

@cstarner
Copy link

Actually, after poking around some more, there may be a way to accomplish this. I need to mess around with it, and will report back here

@cstarner
Copy link

After poking around a bit, I believe that I can capture the relevant changes in EnvVars that the virtualenv makes, and make those changes available within the body of withPythonEnv. Doing so would allow sh and bat steps to access the virtualenv as requested.

Life has been getting in the way recently, and I apologize for the delay. As soon as I get a little extra time I will knock this out

@r4v5
Copy link
Author

r4v5 commented Nov 18, 2017

Awesome news about possibly being able to do it with environment variables! I understand life getting in the way. Take your time; in the meantime, it's just two more characters for us to type, it's not more important than the rest of your life.

cstarner added a commit that referenced this issue Aug 29, 2018
This was a pretty major change to the plugin. In order to bring this
plugins functionality more in line with Jenkins idioms, I changed the
withPythonEnv step to apply environmental variable changes skimmed from
the activiation of the virtualenv. This is how virtualenv works under
the hood when active anyways.

As such, we no longer need the pybat and pysh steps, the regular sh
and bat steps work as intended. These have been removed as part of this
commit
cstarner added a commit that referenced this issue Aug 29, 2018
@cstarner
Copy link

This functionality has been added, and will be released shortly as version 2.0.0

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

No branches or pull requests

2 participants