mibexsoftware / bamboo-plan-dsl-plugin

Configuration as code with a Groovy-based DSL or YAML for Atlassian Bamboo.
https://marketplace.atlassian.com/plugins/ch.mibex.bamboo.plandsl/
Other
40 stars 16 forks source link

Multiple error when trying to import a class #93

Closed drumb3r closed 5 years ago

drumb3r commented 5 years ago

Hi, i got the follow path structure

A) src/main/groovy/plans/build_planDSL.groovy B) src/main/groovy/plans/utilities/MyUtilities.groovy

I just want to import a class file (utilities/MyUtilities.groovy) into build_planDSL.groovy

some of the code in A case:

import utilities.MyUtilities

_project(key: BAMBOO_PROY_KEY, name: BAMBOO_PROYNAME) { _plan(key: BAMBOO_PLAN_KEY, name: BAMBOO_PLANNAME) { _description (BAMBOO_PLANDESCRIPTION) (...)

some of the code line in B case:

package utilities

class Utilities { static void veracodeSAST (Job job, String FILE_PATH, Integer MAX_TIMES, Boolean ENABLED=true) { job.with { description 'Veracode Static Analysis Job'

        tasks {
            custom(pluginKey: 'com.atlassian.bamboo.plugins.scripttask:task.builder.script') {
                description 'Full Veracode SAST'
                enabled ENABLED
                isFinal false
                configure(
                'argument': '',
                'scriptLocation': 'INLINE',
                'environmentVariables': '',
                'scriptBody': 'echo HELLO'
                   )
               }

            artifacts { 
                definition(name: 'Veracode', copyPattern: '**/*.pdf') {
                    location ''
                    shared false
                } 

                dependency(name: 'compile') {
                    destinationDirectory ''
                }
            }
        }
    }
}

But when im trying to import this, i got the erro result from Bamboo: image

Please i just want to import a class into a BambooDSL plan, what im doing wrong?

why im seeing a class named "ch.mibex.bamboo.plandsl.dsl.Stage" ??

Thanks!

mrueegg commented 5 years ago

Hi,

Thanks for your feedback.

To be able to reproduce this problem, could you please attach a screen shot of the seed task configuration?

Also, if you could show me the example DSL file INCLUDING the call to Utilities.veracodeSAST, that would help me as well.

Best regards, Michael

drumb3r commented 5 years ago

Hi @mrueegg

I solved the problem! I was using the "job.with {}" after de method declaration. Instead i change this by using "tasks.with{} and now is working! The next issue that i got is, in MyUtility.groovy i create a lot of class method for use in my main DSL file, exist any other method to create more files and not to create too many methods in MyUtility.groovy file.

by example, creating the classes:

dsls/main.groovy src/main/groovy/utilities/MyUtilities.groovy src/main/groovy/utilities/Class2.groovy src/main/groovy/utilities/Class3.groovy src/main/groovy/utilities/Class....N.groovy

Could be able to perform this import in dsld/main.groovy:

import dsls.utilities.MyUtility import src/main/groovy/utilities/Class2.groovy import dsls.utilities.MyUtility/Class3.groovy import dsls.utilities.MyUtility/Class.....N.groovy

it's could this be possible?

Thanks!

mrueegg commented 5 years ago

Hi @drumb3r

Absolutely, you can have as many utility classes as necessary. Or did you experience a problem?

drumb3r commented 5 years ago

@mrueegg

Im having problem with that, i cannot create another groovy class instead of MyUtility.groovy. I got the following directory structure:

/dsls/mainPlan.groovy /src/main/groovy/utilities/MyUtility.groovy

inside MyUtility.groovy i create the class "MyUtility" and everything works perfectly. The problem occurs when i change the class name from "MyUtility" to "Tools1" and change the filename from MyUtility.groovy to MyUtility2.groovy. Bamboo claims the following error:

image

like i said, if i got the following files with classes:

src/main/groovy/utilities/MyUtilities.groovy                    (class MyUtility / Method: helloPlan)
src/main/groovy/utilities/Class2.groovy                           (class Class2 / Method: helloWorld)
src/main/groovy/utilities/Class3.groovy                           (class Class3 / Method: helloClass)
src/main/groovy/utilities/Class....N.groovy                       (class ClassN / Method: helloMethodN)

in /dsls/main.groovy i would be able to perfom:

import dsls.utilities.MyUtility
import dsls.utilities.Class2
import dsls.utilities.Class3
import dsls.utilities.Class....N

But it's not possible without error...

Have you any example importing more files than the MyUtility.groovy and giving another class name to this files?

Thanks!!

drumb3r commented 5 years ago

@mrueegg can you help me with that?

I need to use multiple groovy files to import in a main file. Im just using the MyUtility.groovy and now i got like 30 method, that too much!. I need to divide this into mutiple files to solve the big monolitic that i have.

So many thanks!

mrueegg commented 5 years ago

@drumb3r Please excuse my late response. I've just tried to use multiple utility classes from my DSL files and in my test case it worked unless the Groovy class and file names do not match. Is there a reason why you would like to use different names for the class and file name (like in your example with Tools1 and MyUtility.groovy)?

drumb3r commented 5 years ago

@mrueegg

I have this one:

image

Of course, i do not have any method named "MyUtility1" just a groovy file named "MyUtility1.groovy" and a class named "MyUtility1" with so many class methods.

I just have a question for you:

No such property: MyUtility1 for class: ch.mibex.bamboo.plandsl.dsl.jobs.Job

Why i got this error message if im not importing that package?

drumb3r commented 5 years ago

@mrueegg you are right!

Now is working for me! Im just having some issue by my part. (called layer 8 issues jjeejeje)

Thanks for you time!!

mrueegg commented 5 years ago

You're very welcome, I'm glad that it is working now.

Best regards, Michael