CloudClientEx.terminateInstance not called when build finished

I have created my own Agent Cloud which seems to work perfectly except one issue. The agent starts correctly at the start of a build, but is not terminated when the build finishes. I have ticked the Terminate Instance: After first build finished checkbox, but terminateInstance is not being called after the build finishes. What am I missing here?

Thanks

2 comments
Comment actions Permalink

Here is my teamcity-clouds.log

[2016-11-24 15:10:07,277] INFO [16-11-24 15:09)] - n.AmazonInstanceMetadataReader - Amazon is not available. Amazon EC2 integration is not active: Failed to connect to http://169.254.169.254/2016-04-19. The host did not accept the connection within timeout of 7000 ms
[2016-11-24 15:11:54,765] INFO [4 Flush Queue 1] - .instances.StartInstanceAction - Starting cloud instance: profile 'xenserver'{id=xs-1}, com.spawtz.teamcity.xenServer.XenServerCloudImage@7a49a6, hash=Gqju0XhlbCBpfTjRxCxYNszjuy3d5GOF, reason=Automatic start: Compatible with queued build Spawtz :: CI(promotionId=17)
[2016-11-24 15:11:57,422] INFO [4 Flush Queue 1] - .server.impl.CloudEventsLogger - Cloud instance entered 'running' state, profile 'xenserver'{id=xs-1}, com.spawtz.teamcity.xenServer.XenServerCloudInstance@60a468
[2016-11-24 15:11:57,423] INFO [4 Flush Queue 1] - .server.impl.CloudEventsLogger - Cloud instance start succeeded: profile 'xenserver'{id=xs-1}, com.spawtz.teamcity.xenServer.XenServerCloudInstance@1ade5a2
[2016-11-24 15:12:00,093] INFO [uled executor 2] - .server.impl.CloudEventsLogger - Cloud instance entered 'running' state, profile 'xenserver'{id=xs-1}, com.spawtz.teamcity.xenServer.XenServerCloudInstance@42c3cf
[2016-11-24 15:12:41,514] INFO [nio-8081-exec-6] - r.impl.DBCloudStateManagerImpl - Image: com.spawtz.teamcity.xenServer.XenServerCloudImage@a508b9, profile: profile 'xenserver'{id=xs-1} was marked to CONTAIN agent
[2016-11-24 15:12:41,517] INFO [nio-8081-exec-6] - .server.impl.CloudEventsLogger - Detected cloud agent "buildagent_192.168.1.40" {id=1}, profile 'xenserver'{id=xs-1}, com.spawtz.teamcity.xenServer.XenServerCloudInstance@9f1162

1
Comment actions Permalink

The agent needs to declare that it requires termination after the first build explicitly in its configuration parameters.

When you start a new cloud instance, you receive a CloudInstanceUserData object that contains necessary parameters and you need to find a way to bypass this information to the VM and read it here. For example: https://github.com/JetBrains/teamcity-vmware-plugin/blob/master/cloud-vmware-agent/src/main/java/jetbrains/buildServer/clouds/vmware/VMWarePropertiesReader.java

Alternatively, you can set the agent configuration parameter jetbrains.buildServer.clouds.CloudConstants#AGENT_TERMINATE_AFTER_BUILD to true manually or based on your own heuristics and that should work either.

Anyway, server decides whether agent should be terminated after the build based on the agent configuration parameters, not based on the profile settings, since they can be changed after VM is launched.

0

Please sign in to leave a comment.