TFS 工作流活动在构建、自定义或固定后调用 REST 服务?

发布于 2024-11-24 08:03:54 字数 148 浏览 4 评论 0原文

我有一个 NuGet 存储库,每次构建后都会获取一个包。我有一项 REST 服务,它是 NuGet 服务器的扩展,它将删除低于指定包的所有包。将房间连接在一起的地毯将是一个可以在构建和部署后调用此 REST 服务的操作。我的问题是,REST 活动是否已经存在,或者我是否需要构建它?

I have a NuGet repo that gets a package after each build. I have a REST service that is an extension to the NuGet server that will delete all packages lower than the one specified. The rug that will tie the room together would be an action that could call this REST service after the build and deploy. My question is, does a REST activity already exist, or do I need to build it?

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

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

发布评论

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

评论(1

入怼 2024-12-01 08:03:54

好吧,我创建了自己的 REST 客户端活动。我确信它有一些错误,但它对我有用。

using System;
using System.Activities;
using System.Net;
using Microsoft.TeamFoundation.Build.Client;

namespace Custom.BuildActivities
{
    [BuildExtension(HostEnvironmentOption.Agent)]
    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class RESTClient : CodeActivity
    {
        public InArgument<Uri> Url { get; set; }
        public InArgument<string> Verb { get; set; }

        public OutArgument<HttpStatusCode> StatusCode { get; set; }
        public OutArgument<string> ErrorMessage { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                Uri url = context.GetValue(this.Url);
                string verb = context.GetValue(this.Verb);

                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.Method = verb;

                HttpWebResponse response = null;
                try
                {
                    response = request.GetResponse() as HttpWebResponse;
                    context.SetValue(this.StatusCode, response.StatusCode);
                }
                catch (WebException webEx)
                {
                    if (webEx.Response != null)
                    {
                        context.SetValue(this.StatusCode, ((HttpWebResponse)webEx.Response).StatusCode);
                    }
                    else
                    {
                        context.SetValue(this.StatusCode, HttpStatusCode.BadRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                context.SetValue(this.ErrorMessage, ex.ToString());
            }
        }
    }
}

Well, I created my own REST client activity. I am sure it has some bugs, but it works for me.

using System;
using System.Activities;
using System.Net;
using Microsoft.TeamFoundation.Build.Client;

namespace Custom.BuildActivities
{
    [BuildExtension(HostEnvironmentOption.Agent)]
    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class RESTClient : CodeActivity
    {
        public InArgument<Uri> Url { get; set; }
        public InArgument<string> Verb { get; set; }

        public OutArgument<HttpStatusCode> StatusCode { get; set; }
        public OutArgument<string> ErrorMessage { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                Uri url = context.GetValue(this.Url);
                string verb = context.GetValue(this.Verb);

                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.Method = verb;

                HttpWebResponse response = null;
                try
                {
                    response = request.GetResponse() as HttpWebResponse;
                    context.SetValue(this.StatusCode, response.StatusCode);
                }
                catch (WebException webEx)
                {
                    if (webEx.Response != null)
                    {
                        context.SetValue(this.StatusCode, ((HttpWebResponse)webEx.Response).StatusCode);
                    }
                    else
                    {
                        context.SetValue(this.StatusCode, HttpStatusCode.BadRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                context.SetValue(this.ErrorMessage, ex.ToString());
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文