Dependent build is not triggered

I have two builds:

- Test
- Phpstan

Phpstan requires artifacts from Test and should be triggered on a successful Test build with the same revision.

This is the snapshot dependency definition on the Phpstan build:

dependencies {
    dependency(Test) {
        snapshot {
            runOnSameAgent = true
            onDependencyFailure = FailureAction.CANCEL
            onDependencyCancel = FailureAction.CANCEL
        }

        artifacts {
            artifactRules = """
                application/configs/di-parameters-local.php => application/configs/
                application/configs/local-public.ini => application/configs/
                application/configs/local-private.ini => application/configs/

                ?:application/models/propel.zip!** => application/models/propel/
            """.trimIndent()
        }
    }
    artifacts(RelativeId("Phpstan")) {
        buildRule = lastFinished()
        artifactRules = "?:application/tmp/phpstan.zip!** => application/tmp/phpstan"
    }
}

When the Test build is triggered via vcs, Phpstan build isn't triggered though. The manual says the build with the snapshot dependency (Phpstan) needs a finishBuildTrigger definition:

https://www.jetbrains.com/help/teamcity/configuring-finish-build-trigger.html#Finish+Build+Triggers+and+Snapshots

If I add this definition in the Phpstan build:

triggers {
    finishBuildTrigger {
        buildType = "${Test.id}"
    }
}

I get the following error:

Kotlin DSL compilation errors

  Compilation error settings.kts[171:9]: Unresolved reference: finishBuildTrigger

  Compilation error settings.kts[172:13]: Unresolved reference: buildType

  Compilation error settings.kts[173:13]: Unresolved reference: successfulOnly

I've tried a lot of variations, but no success, any idea?

0
7 comments

Hi,

If you're defining all builds inside a settings.kts file and not splitting into *.kt classes with BuildType, then you can’t use finishBuildTrigger directly — it's unavailable in settings.kts.

You should move to defining builds using class-based BuildType objects (like above), which gives access to the full Kotlin DSL, including finishBuildTrigger.

By the way, have you tired of resolving it with a local IDE?

Best Regards,
Tom

0

thanks, splitting the build into build types resolves the finishBuildTrigger error

 

still struggling though, even after scanning the kotlin docs and resolving in my local ide…

i have a different BuildType defined in a separate file and would like to use the vcs trigger:

triggers {
    vcs {
        root(GitRepo)
        branchFilter = "+:refs/heads/*"
    }
}

this produces the compilation error

'fun vcs(init: VcsSettings.() -> Unit): Unit' cannot be called in this context with an implicit receiver. Use an explicit receiver if necessary.

Am I missing an import or something else?

0

Hi Martin,

> 'fun vcs(init: VcsSettings.() -> Unit): Unit' cannot be called in this context with an implicit receiver. Use an explicit receiver if necessary.

This error usually means that the vcs function is being called in the wrong context. In TeamCity Kotlin DSL, the correct way to define a VCS trigger inside a BuildType is to use the vcs trigger function provided by the DSL, not a generic vcs function.

Inside your BuildType definition, the triggers block should look like this:

triggers {
    vcs {
        branchFilter = "+:refs/heads/*"
    }
}

Note:

• You do not need to specify the VCS root here if it’s already attached to the build type via the vcs block at the top level of the build type.

• If you need to specify a particular VCS root, you can do so, but the syntax is slightly different.

Example BuildType

object MyBuild : BuildType({
    name = “My Build”
    vcs {
        root(GitRepo)
    }
    triggers {
        vcs {
            branchFilter = "+:refs/heads/*"
        }
    }
})
0

Hi Tom, thanks I appreciate your help on this.

I've tried omitting the VCS root before and I do not see a difference in my declaration in comparison to what you are describing.

This is my complete BuildType Definition (Test.kt):

package _Self.buildTypes

import jetbrains.buildServer.configs.kotlin.*
import jetbrains.buildServer.configs.kotlin.BuildType
import jetbrains.buildServer.configs.kotlin.buildFeatures.commitStatusPublisher
import jetbrains.buildServer.configs.kotlin.buildFeatures.perfmon
import jetbrains.buildServer.configs.kotlin.buildSteps.dockerCompose
import jetbrains.buildServer.configs.kotlin.buildSteps.script
import _Self.vcsRoots.GitRepo

object Test : BuildType({
    name = "Test"

    params {
        param("env.COMPOSE_PROJECT_NAME", "kplus")
    }

    vcs {
        root(GitRepo)
    }

    steps {
        dockerCompose {
            name = "docker build"
            id = "DockerCompose"
            file = ".teamcity/build.yaml"
        }
        script {
            name = "Init App"
            id = "Init_App"
            scriptContent = """
                docker compose -f ./.teamcity/build.yaml exec -T fpm_test php -v
                bash .teamcity/init.sh
            """.trimIndent()
        }
        script {
            name = "PHP Lint"
            id = "Linting"
            scriptContent = """docker compose -f ./.teamcity/build.yaml exec -T fpm_test sh -c 'application/bin/parallel-lint --exclude .git --exclude vendor --exclude public --exclude library ${'$'}(find application/models/propel/build/classes \( -type d -name om -o -type d -name map \) -printf "--exclude %p ") .'"""
        }
        script {
            name = "Yaml Lint"
            id = "yaml_lint"
            scriptContent = "docker compose -f ./.teamcity/build.yaml exec -T fpm_test application/bin/yaml-lint application"
        }
        script {
            name = "PHPUnit"
            id = "PHPUnit"
            scriptContent = "docker compose -f ./.teamcity/build.yaml exec -T fpm_test application/bin/phpunit --configuration=tests/phpunit.xml --teamcity"
        }
        script {
            name = "kitaplus console"
            id = "kitaplus console"
            scriptContent = "docker compose -f ./.teamcity/build.yaml exec -T fpm_test php console"
        }
    }

    triggers {
        vcs {
            branchFilter = "+:refs/heads/*"
        }
    }

    features {
        perfmon {
        }
        commitStatusPublisher {
            vcsRootExtId = GitRepo.id.toString()
            publisher = bitbucketServer {
                authType = vcsRoot()
            }
        }
    }

    artifactRules = """
        application/configs/di-parameters-local.php => application/configs/
        application/configs/local-public.ini => application/configs/
        application/configs/local-private.ini => application/configs/
        application/models/propel => application/models/propel.zip
    """.trimIndent()
})
 

 

0

Hi Martin,

 

I'd like to confirm whether you've imported the jetbrains.buildServer.configs.kotlin.triggers.finishBuildTrigger module in your Phpstan.kt file.

According to the official documentation, the following usage should work:

buildType {
    // Other Build Type settings ...
    triggers {
        // Other Triggers ...
        finishBuildTrigger {
            buildType = "<id of a build configuration>"
            branchFilter = "+:release/*"
        }
    }
}

Could you please double-check the import and ensure the syntax matches the example above? You also can Debug Kotlin DSL Scripts.

Best Regards,

Tom

0

The Phpstan.kt file compiles fine, there is no problem with the finishBuildTrigger anymore (the import is there as well).

The current problem relates to the use of

triggers {
    vcs {
        branchFilter = "+:refs/heads/*"
    }
}

in another build type (Test.kt), see full source in my previous answer.

Trying to debug results in the aforementioned compilation error:

Compilation error _Self/buildTypes/Test.kt[23:9]: 'fun vcs(init: VcsSettings.() -> Unit): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary

0

Hi Martin,

Thanks for your update and confirmation.

It seems that the following import is missing in your Test.kt file:

import jetbrains.buildServer.configs.kotlin.triggers.vcs

Could you please add this import and try again?

Best Regards,

Tom

0

Please sign in to leave a comment.