mulesoft-labs / mule-gradle-plugin

Plugin for building mule apps with the gradle build system.
Apache License 2.0
24 stars 14 forks source link

Change 'defaultDomain' at task execution #57

Closed willis7 closed 9 years ago

willis7 commented 9 years ago

In my Jenkins pipeline I need to change defaultDomain on a per job basis, so that I target different stages in the SDLC. So for dev I may use mule-gradle-sample-project-dev, but for production I may want to use mule-gradle-sample-project.

I have tried 2 methods to achieve this, but neither works. First, I tried passing in: gradlew deploy -x test -Pcloudhub.domains.defaultDomain=mule-gradle-sample-project-dev

Then I tried the following in the code:

cloudhub.domains {
    "${project.name}-dev" username: 'DeployDev', password: System.env.LVDEPLOYDEV_PASSWORD
    "${project.name}-sys" username: 'DeploySys', password: System.env.DEPLOYSYS_PASSWORD
    "${project.name}" username: 'DeployPrd', password: System.env.DEPLOYPRD_PASSWORD
    defaultDomain = project.hasProperty('defaultDomain') ? defaultDomain : "${project.name}"
}

gradlew deploy -x test -PdefaultDomain=mule-gradle-sample-project-dev

What is the preferred approach for this type of use case?

juancavallotti commented 9 years ago

@willis7 the original idea for this DSL was to use your second approach, only one consideration is that, if you set defaultDomain = null then it will use the first one (this is not enforced or guaranteed but as today it does).

I would use the last approach, but also I acknowledge the DSL can be improved to be used with CI.

willis7 commented 9 years ago

@juancavallotti I tried your suggestion, but I get the following error:

:deploy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':deploy'.
> Multiple cloudhub domains found but none selected as default: [${project.name}-sbx, ${project.name}-dev, ${project.name}-sys, ${project.name}-uat]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.693 secs

Where ${project.name} is hidden for security here.

Whilst this is not desirable, the following does work and lets me progress:

defaultDomain = System.env.CLOUDHUB_TARGET

I can inject this for each CI job for now.

juancavallotti commented 9 years ago

@willis7 the following is working for me:

cloudhub.domains {

    chdev username: '', password: ''
    chdevProd username: '', password: ''

    defaultDomain = project.hasProperty('domain') ? project.domain : null
}

And then I use the following command line

gradle deploy -Pdomain=chdevProd

I can see the output:

:build UP-TO-DATE
:deploy
     Uploading file issue57.zip to URL: https://cloudhub.io/api/applications/chdevProd/deploy
willis7 commented 9 years ago

Thanks for having a look. I followed your lead and it passed. I'm surprised you needed to use project in the project.domain I thought this was implied.

Sorry for causing you so many headaches - if its any consolation, myself and our development team love the plugin!

juancavallotti commented 9 years ago

No problem at all, I'm glad to help and I'm glad to hear that kind of feedback.