Require Environment Variable

This rule checks that a specified environment variable is set.

The following parameters are supported by this rule:

  • message - an optional message to the user if the rule fails.
  • variableName - The name of the environment variable to be checked for.
  • regex - an optional regular expression used to check the value of the property.
  • regexMessage - an optional message to the user if the regex check fails.

The regex is applied to the entire value of the environment variable (i.e. using the regex "match" method), and not just a substring of the environment variable value.

Sample Plugin Configuration:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.4.1</version>
        <executions>
          <execution>
            <id>enforce-environment-variable-is-set</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireEnvironmentVariable>
                  <variableName>the_name_you_wish_to_be_checked</variableName>
                </requireEnvironmentVariable>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>