Groovy获取TFS变更集的编辑类型 [英] Groovy get edit type of tfs changeset

查看:96
本文介绍了Groovy获取TFS变更集的编辑类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取tfs变更集文件(我已完成此操作),还需要获取它是使用jenkins服务器上的groovy插件添加还是删除.

I need to get tfs changeset files (I have accomplished this) and also whether it was added or deleted using the groovy plugin on jenkins server.

我无法弄清楚如何访问保存该方法的项目类以获取编辑类型.我尝试了下面的代码,只是无法弄清楚.

I cannot figure out how to access the item class that holds the method to get the edit type. I have tried the below code and just cannot figure it out.

import java.lang.*
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
import hudson.util.*
import hudson.scm.*
import hudson.scm.SubversionChangeLogSet.LogEntry
import hudson.plugins.tfs.model.ChangeSet
import hudson.plugins.tfs.model.ChangeSet.Item
import groovy.util.slurpersupport.GPathResult
import groovy.xml.XmlUtil
import groovy.xml.StreamingMarkupBuilder
import java.io.Serializable
import java.lang.Cloneable
import groovy.xml.MarkupBuilder


// work with current build
def build = Thread.currentThread()?.executable

// get ChangesSets with all changed items
def changeSet = build.getChangeSet()
def items = changeSet.getItems()
println "Affected Paths"

def affectedFiles = items.collect {
 it.getAffectedPaths()
 }

def action = items.getAction()
println action.getEditType

那里有什么主意吗?

推荐答案

根据您的描述,您似乎希望在更改集或更改集中的文件旁边显示状态,以显示操作类型.

According to your description, seems you would like to display the status next to the changeset or files in the changeset that shows what type of action it was.

在TFS中,我们称为changeType,

In TFS we called changeType, Microsoft.TeamFoundation.SourceControl.WebApi.VersionControlChangeType.

而不是在詹金斯中使用Groovy.您也可以通过Rest API来获得.如何查看 VSTS Rest API从中返回特定项变更集API

Instead of using groovy in jenkins. You could also get this through Rest API. How to, take a look at VSTS Rest API return specific item from Changeset API

您应该使用一种方法,该方法返回 EditType .然后index.jelly使用该方法来确定要显示哪个图标.

You should a method that returns an EditType. The method is then used by the index.jelly to determine which icon to display.

在此处查看示例代码:

public EditType getEditType() {
            if (action.equalsIgnoreCase("delete")) {
                return EditType.DELETE;
            }
            if (action.equalsIgnoreCase("add")) {
                return EditType.ADD;
            }
            return EditType.EDIT;
        }

源链接: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆