5

Following https://developer.atlassian.com/bamboodev/bamboo-tasks-api/executing-external-processes-using-processservice I would like to invoke some command using ProcessService bean. The injection as described in the link, does not work. I checked the source of several other plugins at Bitbucket, but each is using the concept as described in the link.

My class:

import com.atlassian.bamboo.process.ProcessService;

public class CheckTask implements TaskType {
    private final ProcessService processService;
    public CheckTask(@NotNull final ProcessService processService) {
        this.processService = processService;
    }

However Bamboo does not find the ProcessService bean and fail with following:

(org.springframework.beans.factory.UnsatisfiedDependencyException : Error creating bean with name 'bamboo.tasks.CheckTask': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.bamboo.process.ProcessService]: : No qualifying bean of type [com.atlassian.bamboo.process.ProcessService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.atlassian.bamboo.process.ProcessService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {})

Am I missing something ? Bamboo version: 5.13.0 AMPS version: 6.2.6

Kousalik
  • 3,111
  • 3
  • 24
  • 46

2 Answers2

3

The solution in the end was quite simple, no oficial docs discuss the solution though. Hope this helps you a bit.

Finally thanks to this post I made it work: https://answers.atlassian.com/questions/33141765/testcollationservice-not-injected-into-tasktype-constructor-on-sdk-bamboo

import com.atlassian.bamboo.process.ProcessService;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;

@Scanned
public class CheckTask implements TaskType {

    @ComponentImport
    private final ProcessService processService;

    public CheckTask(@NotNull final ProcessService processService) {
        this.processService = processService;
    }

The rest of the project was basicaly default, as generated by atlas-create-bamboo-plugin.

Kousalik
  • 3,111
  • 3
  • 24
  • 46
  • Note that the @Autowired is left out intentionally. No need for that. Just to justify my comment under the other answer. – Kousalik Aug 16 '16 at 14:23
1

Try to add in your atlassian-plugin.xml next line

<component-import key="processService" 
        interface="com.atlassian.bamboo.process.ProcessService"/>

That should help you

Solorad
  • 904
  • 9
  • 21
  • 1
    Thanks for your help. The plugin build now unfortunately fails with: atlassian-plugin.xml contains a definition of component-import. This is not allowed when Atlassian-Plugin-Key is set. The Atlassian-Plugin-Key part was generated by the atlas-create-bamboo-plugin. – Kousalik Aug 16 '16 at 08:46
  • 1
    Atlassian has updated recently way how components should be imported. So, component-impot is an old way, but there is new way via spring scanner (http://www.j-tricks.com/tutorials/atlassian-spring-scanner-and-nosuchbeandefinitionexception) which is unfortunetly doesn't work well. Try to find something in your pom.xml about Atlassian-Plugin-Key and remove it or follow documentation on link about new way of component-import – Solorad Aug 16 '16 at 08:52
  • Thanks, there are also 2 links following the error. I am just reading through. Will get back if I figure out something. – Kousalik Aug 16 '16 at 08:53
  • Your link pointed me to a several different articles and how-tos, but still not working. Which leads me back to my orginal solution and problem. This is all interesting but with one presumption to be true. That the atlas-create-bamboo-plugin template is wrong (or not up to date or whatever to call it). Because my plugin is as simple as the Helloworld generated by the SDK. What do you think? – Kousalik Aug 16 '16 at 12:39
  • Got it! I rolled back to the original and started again. Scanned, Autowired and ComponentImport are the answer! Having those and the default stuff from the template - injection works. – Kousalik Aug 16 '16 at 13:21