How to execute buildscript from custom DSL library?
I have the following extension method:
fun BuildSteps.addBuildsteps() {
csharpScript {
name = "ScriptStep"
content = "Console.WriteLine(\"Hello\")"
}
csharpFile {
name = "FileStep"
path = "resources/script.csx"
}
}I built this extension method into a Kotlin library that I uploaded to TeamCity under DSL Libraries. I can access this extension method in my build configs after adding the DSL library as a dependency.
So far, so good.
The first build step is executed successfully. The second one, of course, not. The specified path does not exist in the checkout directory. However, I added the script to my library under resources and also created a resources.xml.
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>resources</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>resources</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
The script also ends up in my jar

How can I specify the path to the script correctly? Is that even possible? Is this even the right use case for DSL Libraries?
I don't want to write the content of the script inline in the build step. Therefore, I also don't want to use recipes. Besides, I want to have versioning so that dependent build configs don't necessarily have to be changed if the call to my script changes. If that's not the right use case for DSL libraries, the following other approaches come to mind:
- I could use git submodules to make my script available for other build configs.
- Since it's C# code anyway, create an application and upload it as a tool.
- Distribute the script as an artifact dependency.
Are there any other, better alternatives? What is the way JetBrains intended for this use case?
Please sign in to leave a comment.
Hi,
DSL Libraries are intended to:
- Provide Kotlin extensions, helper functions, templates, etc.
- Be used at DSL evaluation time (when TeamCity loads/generates .teamcity code).
- Not to ship runtime resources (scripts, executables, configs).
- They’re evaluated server-side, not agent-side.
Therefore, DSL libraries cannot be used as a delivery mechanism for script files.
For more information, please refer to Add Custom Kotlin Libraries.
As you mentioned, you can keep your .csx script(s) in a dedicated repository (or directory), and then:
- Reference them in your build via VCS checkout rules, or
- Use a Git submodule (if you want shared code managed centrally).