以编程方式固定 Teamcity 中的构建

发布于 2024-11-18 04:17:11 字数 54 浏览 2 评论 0原文

是否可以通过编程/自动方式在 Teamcity 中固定构建? 如果部署构建成功,我想固定构建。

Is it possible to pin a build in Teamcity programmatically/automatically?
I want to pin a build if a Deploy-build is successfull.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深海不蓝 2024-11-25 04:17:11

刚刚发现可以通过 REST API
我可以 f.ex 发送这样的 PUT 命令
http://teamcityserver:81/httpAuth/app/rest/builds/ id:688/pi​​n/
然后 ID 为 688 (teamcity.build.id) 的构建将被固定。

Just found out that its possible through the REST API
I can f.ex send a PUT command like this
http://teamcityserver:81/httpAuth/app/rest/builds/id:688/pin/
and then the build with id 688 (teamcity.build.id) will be pinned.

咆哮 2024-11-25 04:17:11

我想用最新的答案来挑战已接受的答案,该答案已使用 TeamCity 9 EAP 4(内部版本 31717)和 8.1.x 进行了测试。

标记和固定可以通过一个简单的插件来实现,该插件仅包含一个事件适配器,如下所示:

package com.foo;

import com.intellij.openapi.diagnostic.Logger;
import jetbrains.buildServer.messages.Status;
import jetbrains.buildServer.serverSide.BuildServerAdapter;
import jetbrains.buildServer.serverSide.BuildServerListener;
import jetbrains.buildServer.serverSide.SRunningBuild;
import jetbrains.buildServer.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Map;

public class MyEventAdapter extends BuildServerAdapter
{

    private final static Logger logger = Logger.getInstance(MyEventAdapter.class.getName());


    public MyEventAdapter(@NotNull EventDispatcher<BuildServerListener> serverDispatcher)
    {
        serverDispatcher.addListener(this);
    }

    @Override
    public void buildFinished(@NotNull SRunningBuild build)
    {
        logger.debug("#");
        logger.debug("# Build finished: ");
        logger.debug("# name: " + build.getBuildTypeName() + ";" +
                     " id: " + build.getBuildId() + ";" +
                     " build number: " + build.getBuildNumber() + "; " +
                     " owner: " + build.getTriggeredBy().getUser().getName());
        logger.debug("# status: " + build.getBuildStatus());
        logger.debug("# ---------------------------------------------------");

        super.buildFinished(build);

        if (build.getBuildStatus().equals(Status.NORMAL))
        {
            if (someConditionCheckWhetherToTagAndPinGoesHere())
            {
                final String tag = "dev";

                // Pin the build:
                if (build.getBuildType() != null && build.getBuildType().getLastChangesSuccessfullyFinished() != null)
                {
                    build.getBuildType().getLastChangesSuccessfullyFinished().setPinned(true, build.getOwner(), "This is a " + tag + " build.");
                }

                // Tag the build:
                build.setTags(build.getOwner(), Arrays.asList(tag));
            }
        }
    }

}

您还需要在 src/main/resources/META-INF/my-plugin.xml 下有一个 Spring 上下文:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="constructor">

    <bean class="com.foo.MyEventAdapter"/>

</beans>

I would like to challenge the accepted answer with an up-to-date answer, which was tested with TeamCity 9 EAP 4 (build 31717) and 8.1.x.

Tagging and pinning could be implemented via a simple plugin that contains just an event adapter such as the following:

package com.foo;

import com.intellij.openapi.diagnostic.Logger;
import jetbrains.buildServer.messages.Status;
import jetbrains.buildServer.serverSide.BuildServerAdapter;
import jetbrains.buildServer.serverSide.BuildServerListener;
import jetbrains.buildServer.serverSide.SRunningBuild;
import jetbrains.buildServer.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Map;

public class MyEventAdapter extends BuildServerAdapter
{

    private final static Logger logger = Logger.getInstance(MyEventAdapter.class.getName());


    public MyEventAdapter(@NotNull EventDispatcher<BuildServerListener> serverDispatcher)
    {
        serverDispatcher.addListener(this);
    }

    @Override
    public void buildFinished(@NotNull SRunningBuild build)
    {
        logger.debug("#");
        logger.debug("# Build finished: ");
        logger.debug("# name: " + build.getBuildTypeName() + ";" +
                     " id: " + build.getBuildId() + ";" +
                     " build number: " + build.getBuildNumber() + "; " +
                     " owner: " + build.getTriggeredBy().getUser().getName());
        logger.debug("# status: " + build.getBuildStatus());
        logger.debug("# ---------------------------------------------------");

        super.buildFinished(build);

        if (build.getBuildStatus().equals(Status.NORMAL))
        {
            if (someConditionCheckWhetherToTagAndPinGoesHere())
            {
                final String tag = "dev";

                // Pin the build:
                if (build.getBuildType() != null && build.getBuildType().getLastChangesSuccessfullyFinished() != null)
                {
                    build.getBuildType().getLastChangesSuccessfullyFinished().setPinned(true, build.getOwner(), "This is a " + tag + " build.");
                }

                // Tag the build:
                build.setTags(build.getOwner(), Arrays.asList(tag));
            }
        }
    }

}

You'll also need to have a Spring context under src/main/resources/META-INF/my-plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="constructor">

    <bean class="com.foo.MyEventAdapter"/>

</beans>
放我走吧 2024-11-25 04:17:11

受到 carlspring 答案的启发,我编写了一个小 teamcity 插件,以编程方式将标签添加到您的构建中:

https:// github.com/echocat/teamcity-buildTagsViaBuildLog-plugin

您可以轻松修改它以固定您的构建。此外,标记成功的构建而不是固定它们并使用标签作为过滤器可能会有所帮助。

Inspired by carlspring's answer, I wrote a little teamcity plugin that programmatically adds tags to your build:

https://github.com/echocat/teamcity-buildTagsViaBuildLog-plugin

You could easily modify it to also pin your build. Furthermore, it might be helpful to tag your successful builds instead of pinning them and use the tag as a filter.

薄荷港 2024-11-25 04:17:11

如果您愿意安装一个插件,我编写了一个插件,能够根据构建功能或系统消息以编程方式标记和固定构建。

https://github.com/ocroquette/teamcity-autopin

另请参阅:https://youtrack.jetbrains.com/issue/TW-38017

If you are willing to install a plugin, I wrote one that is able to tag and pin builds programmatically based on build features or system messages.

https://github.com/ocroquette/teamcity-autopin

See also: https://youtrack.jetbrains.com/issue/TW-38017

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文