diff --git a/build.sbt b/build.sbt index 230f0cc..d287f55 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,7 @@ githubPath := "gatling/gatling-sbt-plugin" libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "3.2.18" % Test, - "io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.0-M11" + "io.gatling" % "gatling-enterprise-plugin-commons" % "1.9.0-M13" ) scriptedLaunchOpts := { diff --git a/src/main/scala/io/gatling/sbt/GatlingKeys.scala b/src/main/scala/io/gatling/sbt/GatlingKeys.scala index 4217167..3cab00a 100644 --- a/src/main/scala/io/gatling/sbt/GatlingKeys.scala +++ b/src/main/scala/io/gatling/sbt/GatlingKeys.scala @@ -129,6 +129,8 @@ object GatlingKeys { |$documentationReference. |""".stripMargin) + val enterpriseDeploy = taskKey[Unit]("Deploy a package and configured simulations") + val assembly = taskKey[File]( "Builds a package for Gatling Enterprise (deprecated, please use 'Gatling / enterprisePackage' or 'GatlingIt / enterprisePackage' instead)." ) diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala b/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala index 3588414..118479c 100644 --- a/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala +++ b/src/main/scala/io/gatling/sbt/settings/gatling/EnterpriseSettings.scala @@ -48,12 +48,14 @@ object EnterpriseSettings { val taskPackage = new TaskEnterprisePackage(config) val taskUpload = new TaskEnterpriseUpload(config, taskPackage) val taskStart = new TaskEnterpriseStart(config, taskPackage) + val taskDeploy = new TaskEnterpriseDeploy(config, taskPackage) Seq( config / enterpriseUrl := new URL("https://cloud.gatling.io"), config / enterprisePackage := taskPackage.buildEnterprisePackage.value, config / enterpriseUpload := taskUpload.uploadEnterprisePackage.value, config / enterpriseStart := taskStart.enterpriseSimulationStart.evaluated, + config / enterpriseDeploy := taskDeploy.enterpriseDeploy.value, config / enterprisePackageId := sys.props.get("gatling.enterprise.packageId").getOrElse(""), config / enterpriseTeamId := sys.props.get("gatling.enterprise.teamId").getOrElse(""), config / enterpriseSimulationId := sys.props.get("gatling.enterprise.simulationId").getOrElse(""), diff --git a/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala new file mode 100644 index 0000000..31f2f58 --- /dev/null +++ b/src/main/scala/io/gatling/sbt/settings/gatling/TaskEnterpriseDeploy.scala @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2024 GatlingCorp (https://gatling.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.gatling.sbt.settings.gatling + +import scala.util.Try + +import io.gatling.plugin.deployment.DeploymentConfiguration +import io.gatling.plugin.model.BuildTool +import io.gatling.sbt.BuildInfo +import io.gatling.sbt.GatlingKeys._ +import io.gatling.sbt.settings.gatling.EnterpriseUtils.* + +import sbt._ +import sbt.Keys._ + +class TaskEnterpriseDeploy(config: Configuration, enterprisePackage: TaskEnterprisePackage) extends RecoverEnterprisePluginException(config) { + val enterpriseDeploy: InitializeTask[Unit] = Def.task { + val logger = streams.value.log + val enterprisePlugin = EnterprisePluginTask.batchEnterprisePluginTask(config).value + val packageFile = enterprisePackage.buildEnterprisePackage.value + val descriptorFile = DeploymentConfiguration.fromBaseDirectory((config / baseDirectory).value) + val artifactId = (config / name).value + val controlPlaneUrl = (config / enterpriseControlPlaneUrl).value + + Try { + enterprisePlugin.deployFromDescriptor( + descriptorFile, + packageFile, + artifactId, + controlPlaneUrl.isDefined, + BuildTool.SBT, + BuildInfo.version + ) + }.recoverWith(recoverEnterprisePluginException(logger)).get + } +}