Run step only if build status is failed

Hello,

I would like to run a build step only if the status of the build is failed. Unfortunately, in the build step configuration, there is only the option to run it "Only if build status is successful".
Is there other way, or a feature request ?

Thanks,
Olivier

3
5 comments

Hi Olivier,

This build feature is not implemented, please vote for the request https://youtrack.jetbrains.com/issue/TW-24782.
Current workaround is to pass a parameter to the next steps on successful build and then performing some logic in the step if the parameter is not set.
Another workaround is to do a REST call from within the build asking the server what the build status is and doing some logic based on the result.

0
Avatar
Permanently deleted user

Hello Alina,

I would prefer not to use the REST API because of the complexity.

But unfortunately, I don't think I can use the first workaround in my case, because the failures I have to deal with don't come from the build steps, but from failed dependencies.

Olivier

0
#!/bin/bash
    set -e -x
    
    declare status=$(curl -v -H "Authorization: Bearer %env.teamcity_internal_api_key%" -H "Accept: application/json" %teamcity.serverUrl%/app/rest/builds/id:%teamcity.build.id%/status)
    
    if [ "$status" = "FAILURE" ]; then
            do you code here
    fi
0

Flasher2085 awesome, needing this so I will try this script. Question: what is the

%env.teamcity_internal_api_key%

value and where can I get it from? 

0

Salvatore121

sorry for my late response

to be able to use TeamCity API you need to create an API token.  A token can be created by clicking on the user name and selecting ‘Access Tokens’ then ‘Create Token’. 

After you can use this token in script but better practice would be to create a variable and place your token there

here , I created variable teamcity_internal_api_key (you can choose any name) and I used it with %env.yourvarname% 

%env.teamcity_internal_api_key%

 

0

Please sign in to leave a comment.