Recommendations for Deployment build config setup
I currently have a project which includes “Build” and “Deploy” configs (among many others). Currently these are completely separate - when you want to Deploy you run that config, with a parameter for the build number that you want to deploy (which is used in an Artifact Dependency).
The “Build” config is triggered every morning with a Schedule trigger, but also is frequently manually triggered by developers.
The “Deploy” config is currently only triggered manually.
What I'd like is for the “Build” Schedule Trigger to automatically trigger the “Deploy” if the build is successful. But, I don't want manually triggered builds to be deployed. I also don't want to add a snapshot dependency to the Build config on Deploy, as in general I don't want running Deploy to trigger a new Build (since the user normally selects the build to upload).
Is there a sensible way to achieve this?
Thanks!
Rob.
Please sign in to leave a comment.
Hi,
> Is there a sensible way to achieve this?
It appears that there is no built-in feature in TeamCity to achieve this functionality directly. However, you can use a custom script to call the "Deploy" build as a workaround. Below are the steps:
Step 1: Indicate Build Trigger Type
In the "Build" configuration, define whether the build is scheduled or manually triggered:
- Create a parameter called
build.triggered.by.schedule
and set its default value to false.Step 2: Configure the Schedule Trigger
- Go to Schedule Trigger settings.
- Under Build Customization, set the parameter build.triggered.by.schedule = true.
- Save the trigger.
Step 3: Add a Custom Script in the Build Configuration
- Add a script step (e.g., PowerShell) at the end of the "Build" configuration.
- Replace the buildTypeId in the script below with the appropriate build type ID of your "Deploy" build configuration.
- Use the provided script to queue the "Deploy" build when the schedule trigger is used.
Add add a customer script(Such as PowerShell) in the last step in the "Build" configuration and replace the buildType Id in the scripts. How to queue a build, please refer to https://www.jetbrains.com/help/teamcity/rest/start-and-cancel-builds.html
Best Regards,
Tom
That looks good. Thanks!
Hi Tom,
Quick follow-up question - I've got that script working with a few edits to set some parameters in the deployment config, however it seems like the system user that's being used for the credentials doesn't have permission to run builds:
PowerShell arguments: -NoProfile, -NonInteractive, -ExecutionPolicy, ByPass, -File, D:\BuildAgent\temp\buildTmp\powershell18048277283180912632.ps1
23:15:38 Invoke-RestMethod : Responding with error, status code: 403 (Forbidden).
23:15:38 Details: jetbrains.buildServer.serverSide.auth.AccessDeniedException: You do not have "Run build" permission in
23:15:38 project with internal id: project20
23:15:38 Access denied. Check the user has enough permissions to perform the operation.
As far as I can see the system user doesn't appear in the Admin→Users panel. Is there a way to add those permissions?
Thanks!
Rob.
Hi Rob,
If the system user lacks permission to run the build, you can generate access tokens for authentication. Follow the guide here: Managing Access Tokens.
Use the following format for the authorization header:
To simplify the process, create a parameter of the "password" type for the token in TeamCity. Learn more here. Then, use the parameter in your scripts, ensuring to update the
$authHeader
as shown below:Best Regards,
Tom