Created
March 10, 2022 13:41
-
-
Save aev-mambro2/e080ea2d52126c3b701a1cd43400dd58 to your computer and use it in GitHub Desktop.
How to deploy from multiple projects to multiple target servers using Gradle CDCI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["server-1", "server-2", "server-3"].each { server -> | |
task "deploy-to-$server" (type: Copy) { | |
description: "Copies the project executables to $server" | |
enabled: true | |
group: "distribution" | |
afterEvaluate { Project project -> | |
from: "$distDir/$distZip" | |
into: "\\\\$server\\share\\${project.name}\\" | |
} | |
} | |
} |
In the Gradle documentation this is known as "dynamic task creation". It doesn't create dynamic tasks... instead it dynamically creates tasks.
We have tried other variations as well. None of these worked:
- put the target server expansion inside the task, inside the project-specific 'afterEvaluate' scope;
- put the target server expansion inside the task, enveloping the project-specific 'afterEvaluate' scope.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A Copy task in Gradle can take input from multiple locations, but it can have only 1 output target. In a multi-project setup, we would hate to set up a separate deployment task for each project to each server. Luckily a Gradle build script is code, too. Code that gets interpreted and executed. Thus we can generate multiple tasks using just 1 declaration. That's what this gist does: it creates a separate deployment task for each of the target servers.
This works for Gradle versions 5.4.1 and up. Maybe earlier, too, but we didn't test that.