0

I am having a Config Parameter in my settings.kts

select(
            name = "TEST_TYPE",
            value = "",
            label = "TEST_TYPE",
            description = "Type of Test(s)",
            display = ParameterDisplay.PROMPT,
            readOnly = false,
            allowMultiple = false,
            options = listOf("E2E-TESTS", "API-TESTS")
        )

When I try to access it, it returns the correct option I have chosen.

steps {
 script {
            scriptContent = "echo %TEST_TYPE%"
        }
}

prints -> E2E-TESTS

But when I try to modify/manipulate the value, it actually returns the label instead of the option I have chosen.

script {
            var test = "%TEST_TYPE%".length
            scriptContent = "echo $test"
        }

prints -> 11 as there are 11 characters in %TEST_TYPE%.

I could not even perform any conditional operations as well.

I don't know why. This is weird and totally blocked by this. Any help will be handy.

Munish Prabhu
  • 39
  • 2
  • 8

1 Answers1

0

I believe that parameters are replaced with their values only inside predefined DSL properties, not any String local variable. So first scriptContent string is evaluated in Kotlin and then (behind the scenes) parameters are substituted, afterwards the resulting script is sent for execution in the command line.

If you need to evaluate length of the parameter value you need to do it by means of the command line script, not Kotlin.

For Linux bash, it should be simply scriptContent = "echo #%TEST_TYPE%" (also there are other ways to do it) For Windows Batch it's much trickier (as there is no built-in way to do it), so you'd better use Powershell for this build step: content = "Write-Host %TEST_TYPE%.Length"

Another option is to use Context Parameters instead of Configuration Parameters, which value could be accessed from Kotlin via DslContext.getParameter("TEST_TYPE"), but they are defined on a project level, and not shown in Run Custom Build dialog.

  • Find the length is just an example. I ultimately want to do a simple string comparison with the TEST_TYPE parameter option like below val testType = "%TEST_TYPE%" ``` if (testType.contains("E2E-TESTS")) { return "e2e-tests/build.gradle" } else if (testType.contains("API-TESTS")) { return "api-tests/build.gradle" } ``` – Munish Prabhu Jan 04 '22 at 15:06
  • So, you've got a Gradle build step, not a Command Line? If it doesn't require anything else than concatenation, `buildFile = "%TEST_TYPE%/build.gradle"` should work fine. Another option is to merge these Gradle buildscripts into one with dedicated tasks for different test types: `tasks = "%TEST_TYPE%"` – Михаил Нафталь Jan 04 '22 at 23:14
  • Thanks for the suggestion. This would ease my problem. It would be great if I able to apply condition on configuration parameters – Munish Prabhu Jan 05 '22 at 07:32
  • You may pass it from TeamCity into Gradle as a [project property](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties) with `gradleParams = "-PtestType=%TEST_TYPE%"`, or as a [task option](https://docs.gradle.org/4.6/release-notes.html#tasks-api-allows-custom-command-line-options) with `gradleParams = "--testType=%TEST_TYPE%"` and define all conditional logic there, on Gradle side – Михаил Нафталь Jan 05 '22 at 19:00