Q: WithPlugin annotation to override existing installed plugin

22 views
Skip to first unread message

Victor Martinez

unread,
Aug 7, 2017, 7:50:47 AM8/7/17
to Jenkins Developers
Hi there,

I'd like to reinstall an old version of a particular plugin in my current Unit Tests, then I can test the behaviour of my plugin with different versions of some dependent plugins.

If I didn't explain myself correctly, this is how far I went:

pom.xml

...
<dependency>
  <groupId>org.jenkins-ci.plugins</groupId>
  <artifactId>groovy</artifactId>
  <version>2.0</version>
  <scope>test</scope>
</dependency>
...

Unit Test:


// this is just using the WithPlugin annotation based on the groovy version 1.30
@WithPlugin
("groovy.hpi")
@Test public void testJobWithSystemGroovy1() throws Exception {
   
FreeStyleProject project = j.createFreeStyleProject("SystemWithSandbox");
    project.getBuildersList().add(new hudson.plugins.groovy.SystemGroovy(new StringScriptSource("println 'hi'"),null,null));
    assertTrue(checker.executeCheck(project));
}

// This is just using the pom dependencies: groovy plugin version 2.0
@Test public void testJobWithSystemGroovy2() throws Exception {
   
FreeStyleProject project = j.createFreeStyleProject("SystemWithSandbox");
    project.getBuildersList().add(new hudson.plugins.groovy.SystemGroovy(new StringScriptSource("println 'hi'"),null,null));
    assertTrue(checker.executeCheck(project));
}



Then the executeCheck method 

public boolean executeCheck(Item item) {
   
boolean found = false;
    PluginWrapper plugin = Jenkins.getInstance().pluginManager.getPlugin("groovy");
    if (plugin==null) {
       
LOG.log(Level.FINE, "Plugin Groovy isn't installed");
    } else {
       
if (plugin.getVersionNumber().isNewerThan(new hudson.util.VersionNumber("1.30"))) {
         
....
}



Unfortunately, WithPlugin doesn't work as I expect since the JenkinsRule takes the pom dependency rather than reinstalling the local one which it's stored under: ./src/test/resources/plugins/groovy.hpi

Any ideas how I can have the same plugin but in different versions while running the Unit Tests with the TestHarness framework?

Thanks

Jesse Glick

unread,
Aug 7, 2017, 9:36:39 AM8/7/17
to Jenkins Dev
On Mon, Aug 7, 2017 at 7:50 AM, Victor Martinez
<victormar...@gmail.com> wrote:
> Any ideas how I can have the same plugin but in different versions while
> running the Unit Tests with the TestHarness framework?

Not supported I think. Why do you care to test against older versions
of another plugin, anyway? If there is some bug in your plugin only
triggered by some condition present in an obsolete version of another
plugin, best to create a test fixture that also triggers the same
condition.

Victor Martinez

unread,
Aug 7, 2017, 12:24:56 PM8/7/17
to Jenkins Developers
I'm linting Jenkins jobs and how some plugins are configured.

For instance:
- groovy plugin version 2.0 uses the script security plugin. While version 1.X no. I'd like to run one test case per version to detect whether they are configured as I expect.
- git plugin version +2.4.1 allows git reference cache repos, so I'd like to test also different versions.


At the moment I need to test it manually with the hpi:run

Does the ATH allow this use case?

Cheers

Jesse Glick

unread,
Aug 7, 2017, 2:42:23 PM8/7/17
to Jenkins Dev
On Mon, Aug 7, 2017 at 12:24 PM, Victor Martinez
<victormar...@gmail.com> wrote:
> - groovy plugin version 2.0 uses the script security plugin. While version 1.X no. I'd like to run one test case per version to detect whether they are configured as I expect.

Just test 2.x and ignore 1.x.

> Does the ATH allow this use case?

Not really.
Reply all
Reply to author
Forward
0 new messages