Disclosure: I've created Java library which deals with this issue: https://github.com/AutomatedOwl/allure-environment-writer
It uses TransformerFactory to write the environment.xml to the allure-results path in any stage of the test. It also checks for the directory existence in case running from cleaned build.
Usage example:
import static com.github.automatedowl.tools.AllureEnvironmentWriter.allureEnvironmentWriter;
public class SomeTests {
@BeforeSuite
void setAllureEnvironment() {
allureEnvironmentWriter(
ImmutableMap.<String, String>builder()
.put("Browser", "Chrome")
.put("Browser.Version", "70.0.3538.77")
.put("URL", "http://testjs.site88.net")
.build(), System.getProperty("user.dir")
+ "/allure-results/");
}
@Test
void someTest() {
Assert.assertTrue(true);
}
}