How to delete a changeset

Document ID : KB000057554
Last Modified Date : 03/10/2018
Show Technical Document Details
Introduction:

Issue

A wrong artifact was referenced in the commit message and now this artifact has a? changeset associated with it. How to delete or unlink a changeset? There is no "Delete" option in the Changeset tabs of User Stories and Defects.
 

Resolution

Changesets can be created and deleted via Web Services API. There are no equivalent options in the UI. Editor rights are sufficient

In this example we create a new changeset using a curl command. It is more likely that the changeset that you would like to delete has been created by one of the CA Agile Central's source code integrations, but for the purposes of this article it makes no difference whether a changeset was created via a connector, custom app or by hitting the create endpoint directly.
In this example curl command uses Api Key for authentication.
curl --header "zsessionid:_abc123" -H "Content-Type: application/json" -d"{\"Changeset\":{\"Revision\":\"1\",\"SCMRepository\":\"/scmrepository/16953479942\",\"CommitTimestamp\":\"2014-12-17\",\"Message\":\"worked on DE4\",\"Artifacts\":{\"Artifact\":\"/defect/12365972343\"}}}" https://rally1.rallydev.com/slm/webservice/v2.0/changeset/create


Changeset is created successfully:

User-added image
Now we are going to delete it. To delete a changeset we need to identify it by ObjectID. Here is an example of a WS API query:
(Message = "worked on DE4")

User-added image


Now we can delete the changeset. Here is the command:
curl --header "zsessionid:_abc123" -H "Content-Type: application/json" -X DELETE https://rally1.rallydev.com/slm/webservice/v2.0/changeset/27157081517

The absence of WS API errors and curl errors indicates a success:
{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [],"Warnings": []}}

The changeset is gone:

User-added image


Below is a Ruby code fragment example that bulk-deletes changesets returned by a query
(Message contains \"DE4\")

Warning: this code deletes data. Make sure that the query returns the changesets you intend to delete!
@rally = RallyAPI::RallyRestJson.new(config)


#find changesets that meet criteria
query = RallyAPI::RallyQuery.new()
query.type = "changeset"
query.fetch = "ObjectID,Message"
query.query_string = "(Message contains \"DE4\")"

results = @rally.find(query)
changesets_to_delete = [];
results.each do |c|
  puts "ObjectID: #{c["ObjectID"]}, Message: #{c["Message"]}"
  c.read
  changesets_to_delete << c
end

#delete changesets
changesets_to_delete.each do |c|
  puts "deleting... #{c["_ref"]}"
  c.delete
end

Here is a screenshot of Changesets to be deleted before the code is run:

User-added image

and the output in the terminal as the code runs:

User-added image

After the page in CA Agile Central is refreshed, the two changesets are gone:


User-added image

The full code example is available in this github repo.
 
Instructions:
Please Update This Required Field