I am writing a gradle custom plugin and the requirement is to fail build conditionally based on a parameter.
To fail the build i am throwing GradleException. If the property is not set, i want to log the reason and stop executing the plugin. Is there anyway other than System.exit?
I ended up throwing StopActionException when i need to stop action without failing the build.
Related
I have some tests that need to check if the main code did a System.exit(...). This works very nicely with suggestions from https://stackoverflow.com/a/309427/1023341. But when running these tests in Jenkins (in stead of in my IDE Eclipse) and later when trying them on the command-line using Maven-Surefire (as Jenkins does) the tests fail without telling me why. It only tells me: Error occurred in starting fork, check output in log.
When setting a SecurityManager during JUnit (5) using System.setSecurityManager and using Surefire plugin, you should restore the SecurityManager after the test.
SecurityManager origSecurityManager = System.getSecurityManager();
try {
// ... code under test here ...
} finally {
System.setSecurityManager(origSecurityManager);
}
or some other more suitable form. This makes sure that Maven-Surefire-plugin stays happy.
Edit for suggested pre-baked solutions:
There are two pre-baked libraries for this:
junit5-system-exit
system-lambda
As the name suggests: the system-lambda is a Java 8+ solution. Both are JUnit 5 compatible. My personal preference lies with the lambda solution.
More background information
I have created a maven plugin whose purpose is to bring up an application, which run in pre-integration phase, it sets a system level prop called "LOOKUPGROUPS". I want this property to be available in my integration tests. However everytime i try to get this property it always comes as null.
Also i have noticed in my task manager that whenever my build reaches the integration stage and my integration tests start to execute a new java process comes up.
I think it works by adding properties in MaverSession.getUserProperties.
I created some system properties in TC build configuration.
The value of these properties are passed to a maven configuration this way:
clean test -Dargument1=%system.property1% -Dargument2=%system.property2%
And this works as expected.
What I want to do now is to modify the value of the system properties when the build finish, so the next build will get these values.
Is it possible to do that programmatically, through Java or using Maven?
Is this the correct approach?
You can define build properties for this. Once your build finishes, you can craft a Maven plugin that sends a post request to TeamCity and alters the values for these build properties for the build type.
If I where you, I would craft maven task, which will update your properties via TeamCity restAPI on build completion.
It looks like mostly elegant way to do this task.
Full explanation for restAPI plugin could be found here:
http://confluence.jetbrains.com/display/TW/REST+API+Plugin
What is needed for your use-case is described here:
Build Configuration And Template Settings
Build configuration parameters: GET/DELETE/PUT http://*teamcity_url_goes_here*/httpAuth/app/rest/buildTypes//parameters/ (accepts/produces text/plain)
You could craft a request to update your parameters.
One more interesting thing: If you want to execute requests to REST API inside a TeamCity build running on the same server, you can use %teamcity.serverUrl% predefined parameter to construct URL
I have a Spring project (Apache CXF, Spring, Hibernate, Maven ...) hosted on BitBucket and I'm trying to use Bamboo as my CI server. My idea is deploying the code directly to Heroku from Bamboo so that deploying time is automated.
I made a plan with a couple of tasks to achieve this. First I have a Source Code Checkout task and a builder task. Both of them are working, code is compiling and test are passing, I can see that in the task log. The problem is that Bamboo doesn't seem to recognize the tests (it marks the task are testless).
I have also tried to create a new JUnit test task and it's even worst. Log shows that everything is working properly but Bamboo marks the plan as a failure after the test task is executed.
Any ideas?
Not sure which version of Bamboo you're using, but in the version that we have, you have to turn on unit test result evaluation on the Builder tab. Please see the attached screenshot, and make sure that this is enabled, and the directory setting is pointing to the directory where Maven Surefire creates the test results (in XML format).
With the Jenkins plugin "Parameterized Trigger Plugin" you can pass job parameters to a downstream job. You have to specify the downstream job which I don't know in my case.
In am using all maven jobs with the setting "Build whenever a SNAPSHOT dependency is built" enabled such that the downstream jobs are automatically detected and run by Jenkins it self.
A such, I don't know the downstream job such that I can't specify it when using the "Parameterized Trigger Plugin".
How can I pass all parameters value's to all the detected jenkins maven jobs?
Sorry, but I have to disappoint you. There is no way to add parameters to the Build whenever a SNAPSHOT dependency is built. There is a little manual work to do to "add this functionality":
Go to the triggered Job with parameter
Go to each Upstream-Job and add a post build action: Trigger parameterized build on other projects
Its not the ideal solution. But the plugin doesn't support this use case.