8000 Add Environment Variable for each GV Variable by gep13 · Pull Request #271 · GitTools/GitVersion · GitHub
[go: up one dir, main page]

Skip to content

Add Environment Variable for each GV Variable #271

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

Closed
wants to merge 1 commit into from

Conversation

gep13
Copy link
Member
@gep13 gep13 commented Oct 6, 2014

In a recent Pull Request (#262), the decision was taken to, in the absence of setParameter being available in AppVeyor, to create environment variables that could then be accessible in the remainder of Build Script. I would like to suggest that this also makes sense for TeamCity.

In my scenario, I want to use:

/output buildserver

but use the generated variables later in my psake build script. In order to do this, I have to call GitVersion twice.

Using this approach should mean that I can access the created Environment Variables later in my psake script when I need them.

Does that make sense?

In a recent Pull Request (GitTools#262), the decision was taken to, in the absence of setParameter being available in AppVeyor, to create environment variables that could then be accessible in the remainder of Build Script.  I would like to suggest that this also makes sense for TeamCity.

In my scenario, I want to use:

```/output buildserver```

but use the generated variables later in my psake build script.  In order to do this, I have to call GitVersion twice.

Using this approach should mean that I can access the created Environment Variables later in my psake script when I need them.

Does that make sense?
@robdmoore
Copy link

I thought there was a reason that -exec and -proj exist such that you can access env vars and that there was some reason the vars wouldn't be usable (e.g. they would propagate out of the process) if set like this?

On 6 Oct 2014, at 9:51 pm, Gary Ewan Park notifications@github.com wrote:

In a recent Pull Request (#262), the decision was taken to, in the absence of setParameter being available in AppVeyor, to create environment variables that could then be accessible in the remainder of Build Script. I would like to suggest that this also makes sense for TeamCity.

In my scenario, I want to use:

/output buildserver

but use the generated variables later in my psake build script. In order to do this, I have to call GitVersion twice.

Using this approach should mean that I can access the created Environment Variables later in my psake script when I need them.

Does that make sense?

You can merge this Pull Request by running

git pull https://github.com/gep13/GitVersion patch-4
Or view, comment on, or merge it at:

#271

Commit Summary

Add Environment Variable for each GV Variable
File Changes

M GitVersionCore/BuildServers/TeamCity.cs (2)
Patch Links:

https://github.com/Particular/GitVersion/pull/271.patch
https://github.com/Particular/GitVersion/pull/271.diff

Reply to this email directly or view it on GitHub.

@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

In my case, I am executing the call to GitVersion from within the same psake script, that I later want to use the variables that are created by GitVersion. You can see an example of this here:

https://github.com/chocolatey/ChocolateyGUI/blob/develop/BuildScripts/default.ps1#L182

As a result, I don't have the option to use /exec or /proj. Unless I am missing something.

@JakeGinnivan
Copy link
Contributor

Have you tested this?

From what I understand your psake script executes GitVersion which sets the environmental variables then the process exists and those env variables are not available in psake.

A process cannot set a parent processes env variables.

@JakeGinnivan
Copy link
Contributor

AppVeyor actually collects the environmental variables and promotes them afaik

@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

Tested which part? The TeamCity alteration, or the AppVeyor one?

I was waiting on the next release of GitVersion to test properly on AppVeyor, since the Pull Request was accepted.

I haven't tested on TeamCity yet, but I will. Wanted to start the conversation to see if I was barking up the wrong tree :-)

@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

@JakeGinnivan I have just tested the AppVeyor implementation, and it looks like calling Environment.SetEnvironmentVariable it not going to be enough, we are going to have to do something else, and most likely do something else for TeamCity as well.

Does anyone have any thoughts as to what that "something" would be? I would really like to avoid having to call GitVersion twice, as I think that this it just plain wrong. Surely there is something that can be done to set the Variables from within GitVersion /output buildserver and then consume then immediately within the same psake, or another type of, build script.

@JakeGinnivan
Copy link
Contributor

For shouldly I call GitVersion then parse the json to get the variables I want.

https://github.com/shouldly/shouldly/blob/master/build/rakelib/version.rake

@gep13
8000 Copy link
Member Author
gep13 commented Oct 6, 2014

@JakeGinnivan yes, I have seen that approach, and that is actually what I am doing in the second call to GitVersion. That approach is fine, but then you have to remember to make the call to set the Build Number, etc, thing that the /output buildserver is doing for you.

It almost seems as though, at least to me, that there is a use case for having:

  • /output json
  • /output buildserver
  • /output combined

Where you get both things.

@gep13
Copy link
Member Author
gep13 commented Oct 6, 2014

@JakeGinnivan also, for AppVeyor, I have to first call /output buildserver as it needs to check out fake Pull Request branch, something which doesn't happen when using /output json

@JakeGinnivan
Copy link
Contributor

We probably need to do the branch normalisation when using /output json..

@gep13
Copy link
Member Author
gep13 commented Oct 7, 2014

We probably need to do the branch normalisation when using /output json..

Yip, that would work to.

@gep13
Copy link
Member Author
gep13 commented Oct 8, 2014

I am going to close this PR as this suggested implementation simply wouldn't work as suggested here. Some additional work would be required as suggested by @JakeGinnivan to add branch normalisation when called with /output json, or at least provide a flag that would allow this to be called if/when required.

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.

3 participants
0