sameChainOrLastFinished() questions

Hi Jetbrains,

I'm tempted to use the sameChainOrLastFinished() method for a buildRule in my artifact dependency dsl, but I still have a few questions, perhaps you could help me out?

My dependencies block:

dependencies {
    dependency(OtherBuild) {
        snapshot {
            onDependencyFailure = FailureAction.CANCEL
        }

        artifacts {
            buildRule = sameChainOrLastFinished()
            artifactRules = "..."
        }
    }
}

What I would like to know is:

  1. is sameChainOrLastFinished() the same as Build from the same chain mentioned here?
  2. does sameChainOrLastFinished() only use Suitable Builds that were chosen for the snapshot dependency, in addition to builds from the same chain? Or does it consider other branches/builds too?

Essentially, what I would like is for the artifact dependency to be obtained from the same chain, or from some other branch, but only if it was built for the same git commit. Should I use sameChainOrLastFinished() here, and if not, what would be your recommended approach?

Thanks,

Guno

0
10 comments
Hi Guno,

1. Yes, it is the same.
2. It will take into account only builds that are in the same chain, i.e., if you enable the "Do not run new build if there is a suitable one" option in your snapshot dependency, it will consider suitable builds. If not, only the build that was run as the part of the chain.

I assume that the "Latest finished build" (lastFinished(branch: String? = null)) with a snapshot dependency configured will suit your scenario: https://www.jetbrains.com/help/teamcity/kotlin-dsl-documentation/root/artifact-dependency/last-finished.html.
Please let me know if it works for you.

Best regards,
Anton
0

Thanks Anton!

I tried the following earlier, but found that it sometimes didn't work properly; the artifact could not be resolved as a suitable build from the default branch was used, and the default branch didn't correspond with %teamcity.build.branch%. Or, at least, that is my understanding of it. Does that make sense?
And should I prefer lastFinished(branch: String? = null) over sameChainOrLastFinished(), or would both suit my scenario?

dependencies {
    dependency(OtherBuild) {
        snapshot {
            onDependencyFailure = FailureAction.CANCEL
        }

        artifacts {
            buildRule = lastSuccessful("%teamcity.build.branch%")
            artifactRules = [...]
        }
    }
}
0
Dear Guno,

In the code you've attached, you are using lastSuccessful(), not lastFinished(). I still think that lastFinished() should work for you.
If it is not working for some scenarios, please provide details. I.e., the branch you were building, the branch rule specified in the lastFinished() argument, and expected and actual results.

Best regards,
Anton
0

Hello Anton,

Sorry for the delay; just got around to looking at this issue again.

I'm now using lastFinished("%teamcity.build.branch%"). I'm still getting the error ‘Failed to resolve artifact dependency’; The dependencies tab of the build shows that it is using a suitable build from the default (master) branch as snapshot dependency (which is fine, as that was the same commit).
Is this because I'm passing the current branch to lastFinished()? I'm doing this because otherwise it would only consider the default branch (documentation says: if not specified only builds from the default branch are matched) and I want it to consider my current branch as well.

dependencies {
    dependency(OtherBuild) {
        snapshot {
            onDependencyFailure = FailureAction.CANCEL
        }

        artifacts {
            buildRule = lastFinished("%teamcity.build.branch%")
            artifactRules = [...]
        }
    }
}
 

 

0
Hi Guno,

I didn't have a chance to test it on my side yet, but from what I can see, you have the following:
```
buildRule = lastFinished("%teamcity.build.branch%")
```

The lastFinished() should take the branch rule as an argument. For this configuration, it should be:
```
buildRule = lastFinished("+:%teamcity.build.branch%")
```

Could you check if this works for you?

Best regards,
Anton
0

The lastFinished() should take the branch rule as an argument. For this configuration, it should be:
```
buildRule = lastFinished("+:%teamcity.build.branch%")
```

I tried this, and now I'm seeing Illegal status [404] while downloading when it tries to download the artifact. 
Navigating to the url that is logged shows me Could not find build by revision rule: latest.lastFinished, branch: +:my-branch.

I'll try soon without passing any branch at all to lastFinished(), perhaps that will just work, and my assumption about having to pass in my branch is incorrect.

Regards,
Guno

0
Dear Guno,

I got the following from my tests:
1. Build1 has a snapshot dependency on Build.
2. Build1 has an artifact dependency on Build. The following config gets the artifact dependency resolved:
            artifacts {
                buildRule = lastFinished("+:%dep.TeamCityVcs_Build.teamcity.build.branch%")
                artifactRules = "+:test.txt"
            }
You need a snapshot dependency to access the build branch parameter (you need to take it from the dependent build, not from a current one, i.e., %teamcity.build.branch%, because it is unknown at the time of the build start).

The problem with this is that it is basically the same as sameChainOrLastFinished() because it will always use the last finished build from the same chain (because you specified the same branch, and snapshot dependency will find a suitable build, or run a new one, on the same branch).

Best regards,
Anton
0

Cool, thanks. 

I'll go for lastFinished() without passing an argument, as that seems to work quite well \o/

Thanks once again for your help!

0

Found out that it still doesn't do exactly what I need; lastFinished() seems to bring in artifacts from master that are from another commit.

Instead, I'm now using sameChainOrLastFinished() and that seems to work fine.

0
Hi Guno,

I'm glad you've found a setup suitable for your scenario.

Best regards,
Anton
0

Please sign in to leave a comment.