Path for loading files in same repo as kotlin DSL
I want to load scripts into my script section of a build from an external file. The file is included with the rest of my .teamcity directory in my repo. I am importing file to load the contents of the file during the DSL run. I have chosen to import scripts instead of pasting them into the DSL as a string so that I can still execute and test them without copying/pasting etc... It also comes with the benefits of editors keeping debugging/syntax highlighting/etc.. when working with the script file.
My path looks like this:
.teamcity
├── Build
│ ├── Project.kt
│ ├── buildTypes
│ │ ├── Build_Build.kt
│ │ └── cool_script.sh
│ ├── settings.kts
│ └── vcsRoots
│ └── Build_GitGithubComBuildGit.kt
├── Build_dsl.iml
├── pom.xml
My DSL looks like this:
import java.io.File
import jetbrains.buildServer.configs.kotlin.v2017_2.*
import jetbrains.buildServer.configs.kotlin.v2017_2.buildSteps.script
object Devops_Teamcity_Metarunners_Build : BuildType({
uuid = ""
id = "Build"
name = "Build"
description = "Build Stuff"
vcs {
root(Build.vcsRoots.Build_GitGithubComBuildGit)
}
steps {
script {
name = "Run this cool script"
scriptContent = File("./cool_script.sh").readText()
}
}
When I load this DSL in TeamCity, I get this error:
Current Status:
[16:17:01]: Failed to apply changes from VCS to project settings (revision 237fa4ebcdb148a54277d263257196094e9ae15c): java.lang.reflect.InvocationTargetException. Please fix the errors in VCS and commit again.
Build: Build.buildTypes.Build_Build$1$2$3 [30]: java.io.FileNotFoundException: ./cool_script.sh (No such file or directory)
So now I am left wondering where this file actually lives in relation to the "working space" of the DSL execution task and how to target it.
Please sign in to leave a comment.
Hi,
TeamCity can read files just fine, but as in every other java application, it's not run from within the folder that contains the specific folder, but the folder that contains the whole project. In this case, either add "Build/buildTypes/" to the file path or move the file to the root of the folder.