Val from param to build steps

Answered

Hello!

I have a question about parameters that can be passed to variables and their further use.

I have a code:

params {
text(name: "PARAMS_NAME", value: "smth")
}

val smthVAL="%smth%".smthmethod()

steps {
script {
scriptContent = "echo $smthVAL"
}
}

Now I always get a empty $smthVAL
What needs to be done to be able to process the parameter in a variable and put the processed parameter in the build step?

1
2 comments
Avatar
Fedor Rumyantsev

Hello!

You could amend the DSL as following:

val smthVAL = "someCustomValue"

project {
buildType {
steps {
script {
scriptContent = "echo %myCustomParameter%"
}
}

params {
text(name = "myCustomParameter", value = smthVAL)
}

requirements {
exists("AWS_AGENT")
}
}
}

As a result, smthVAL will be evaluated before the compilation of DSL and its value will be used to set the value of myCustomParameter. The smthVAL is a variable in the DSL which would not be available in the TeamCity context; the myCustomParameter is a build parameter which would have the same value as smthVAL, and it could be referenced in the TeamCity build context. As you can see, scriptContent references the myCustomParameter in this example.

I hope this helps! 

1

Thank you for the answer!

0

Please sign in to leave a comment.