Groovy get edit type of tfs changeset

十年热恋 提交于 2019-12-25 00:43:02

问题


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

Any ideas out there?


回答1:


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.

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

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


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

Take a look at the sample code here:

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

Source Link: jenkinsci/tfs-plugin



来源:https://stackoverflow.com/questions/49779462/groovy-get-edit-type-of-tfs-changeset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!