BrightLight / RepoCop

RepoCop is a repository hook framework written in C#
3 stars 2 forks source link

Implement support for environment variables #13

Closed steffen-wilke closed 6 years ago

steffen-wilke commented 6 years ago

Currently, the HookConfig only allows for absolute path configurations. It would be useful to support environment variables to allow making the configuration more generic and independent on the machine it is executed on. This should be implemented for all file/folder configurations in the config, but is particularly useful for instructions that execute another script or refer to some file, e.g.:

Current State:

<MailInstruction FromMailAddress="test@email.de" ToMailAddresses="#author#@email.de" CcMailAddresses="test@email.de" Subject="##revision#" BodyTemplateFile="c:\Programme\email-templates\messagebody.txt">
  <ChangedPathCondition ChangedPathRegExPattern="/repo/trunk/somefolder" />
</MailInstruction>

Target State:

<MailInstruction FromMailAddress="test@email.de" ToMailAddresses="#author#@email.de" CcMailAddresses="test@email.de" Subject="##revision#" BodyTemplateFile="${MY_SCM_MAILS}\messagebody.txt">
  <ChangedPathCondition ChangedPathRegExPattern="/repo/trunk/somefolder" />
</MailInstruction>
steffen-wilke commented 6 years ago

This can also be very useful for conditions. There could be an EnvironmentCondition that checks whether an environment variable currently has a certain value. This would allow for something like:

<FailInstruction Message="MyPath is currently locked.">
  <Conditions Type="And">
    <EnvironmentCondition Variable="MY_PATH_LOCKED">1</EnvironmentCondition> 
    <ChangedPathCondition ChangedPathRegExPattern="/mypath/.*" />
  </Conditions>
</FailInstruction>
BrightLight commented 6 years ago

I'm not sure that an EnvironmentCondition would be of much use. RepoCop is called from the subversion server, which typically runs as a (Windows) service. Therefore the environment variables depend on the user that is running the service and I'm not sure if simply changing them when logged-in as that user will immediately make this process see the new environment settings. I have my doubts.

BrightLight commented 6 years ago

Why use ${MY_SCM_MAILS} as the syntax for environment variables? I think for Windows it's usually %MY_SCM_MAILS% and Environment.ExpandEnvironmentVariables could be used. That's the option I'm probably going to use.

steffen-wilke commented 6 years ago

I'm not sure that an EnvironmentCondition would be of much use.

I agree with the potential complications here. Maybe a even more general CommandLineCondition might cover the requirement of having "more sophisticated" conditions. But that's a different topic.

Why use ${MY_SCM_MAILS} as the syntax for environment variables?

Sorry, I had the JenkinsFile syntax in mind when writing this. Of course, the default Windows syntax makes more sense here.

BrightLight commented 6 years ago

Should work now.