<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nuno Barreiro 🇵🇹🇪🇺 @ Lisbon</title>
    <description>The latest articles on DEV Community by Nuno Barreiro 🇵🇹🇪🇺 @ Lisbon (@nuno_barreiro).</description>
    <link>https://dev.to/nuno_barreiro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F252577%2Fbb554b78-976e-4849-b39e-f40020e0ec3c.jpg</url>
      <title>DEV Community: Nuno Barreiro 🇵🇹🇪🇺 @ Lisbon</title>
      <link>https://dev.to/nuno_barreiro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nuno_barreiro"/>
    <language>en</language>
    <item>
      <title>Cleanup Azure DevOps pipelines retained by releases</title>
      <dc:creator>Nuno Barreiro 🇵🇹🇪🇺 @ Lisbon</dc:creator>
      <pubDate>Wed, 22 Dec 2021 15:55:38 +0000</pubDate>
      <link>https://dev.to/nuno_barreiro/cleanup-azure-devops-pipelines-retained-by-releases-4d1e</link>
      <guid>https://dev.to/nuno_barreiro/cleanup-azure-devops-pipelines-retained-by-releases-4d1e</guid>
      <description>&lt;p&gt;One situation I've come across a while ago was not being able to remove some deprecated pipelines due to the following error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J5Tx7F7Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://nunobarreiro.com/images/devops-pipeline-retention-lease-error-onremoval.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J5Tx7F7Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://nunobarreiro.com/images/devops-pipeline-retention-lease-error-onremoval.png" alt="One or more builds associated with the requested pipeline(s) are retained by a release. The pipeline(s) and builds will not be deleted." width="880" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Going through the &lt;a href="https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/get?view=azure-devops-rest-6.0"&gt;builds REST documentation&lt;/a&gt;, I was able to check that Builds do have a property "retainedByRelease". Not only that, but digging further and looking at the &lt;a href="https://docs.microsoft.com/en-us/rest/api/azure/devops/build/leases?view=azure-devops-rest-6.1"&gt;leases REST documentation&lt;/a&gt; I also noticed a boolean property named "protectPipeline" that, according to its very relevant description states that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If set, this lease will also prevent the pipeline from being deleted while the lease is still valid.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now I was finally getting somewhere, and I've attempted to patch the lease and set that property to false. Surprised, or maybe not, when you set that property to false for all the leases associated with the build, then the build own property "retainedByRelease" also turns out to false, allowing you to finally delete it permanently!&lt;/p&gt;

&lt;p&gt;To automate things, since I had multiple builds with the same state, I've created the below python script, that you are invited to read and use. &lt;br&gt;
At the time I was using &lt;a href="https://www.telerik.com/fiddler"&gt;Fiddler&lt;/a&gt; to check the requests, but you can remove the "fiddler_proxies" related stuff from there if you don't need that.&lt;/p&gt;

&lt;p&gt;Please follow the &lt;a href="https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&amp;amp;tabs=preview-page#create-a-pat"&gt;instructions&lt;/a&gt; on how to create a Personal Access Token and encode it using a base64 encoding tool like &lt;a href="https://www.base64encode.org"&gt;this&lt;/a&gt; one.&lt;/p&gt;

&lt;p&gt;Make sure to fill in the "project_url", the "encoded_pat" and the "build_definition_ids" variables, before running the script. You can get the build IDs from the URL when you enter a build definition using the DevOps portal&lt;/p&gt;

&lt;p&gt;The project url can also be get from the address bar, and for this script it needs to be in the format: &lt;code&gt;https://dev.azure.com/{org name}/{project name}&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
      <category>azure</category>
      <category>devops</category>
    </item>
    <item>
      <title>Delete Azure DevOps project wiki using Az CLI</title>
      <dc:creator>Nuno Barreiro 🇵🇹🇪🇺 @ Lisbon</dc:creator>
      <pubDate>Thu, 09 Dec 2021 23:12:45 +0000</pubDate>
      <link>https://dev.to/nuno_barreiro/delete-azure-devops-project-wiki-using-az-cli-4535</link>
      <guid>https://dev.to/nuno_barreiro/delete-azure-devops-project-wiki-using-az-cli-4535</guid>
      <description>&lt;p&gt;If you use &lt;a href="https://dev.azure.com"&gt;Azure DevOps&lt;/a&gt;, then it's possible that you've come across with this screen when you select the Wiki option in the Overview left icon:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AcgnulBG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8rdfs4f9x9quycjsbft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AcgnulBG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8rdfs4f9x9quycjsbft.png" alt="Azure DevOps wiki screen" width="434" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those that are not familiar with this feature, if you select the option "Create project wiki", Azure DevOps will immediately, and without requiring any kind of confirmation, present you with an online editor where you can right away start writing and publishing content to your newly created wiki. &lt;/p&gt;

&lt;p&gt;If on the other hand you select the "Publish code as wiki" option, you'll be presented with a screen where you can select a repository, branch and folder, that will serve as the root folder for your wiki. This is a great scenario because in the same DevOps project you can have multiple wikis, hosted in different repos or in different folders of a single repo.&lt;/p&gt;

&lt;p&gt;One thing that both options have in common is that behind the scenes the wiki is just markdown files. With the second option you chose where those files are stored but with the first one DevOps will create a default wiki repository that you apparently can't control in any way using the DevOps interface.&lt;/p&gt;

&lt;p&gt;In my specific case that was a problem because I accidently clicked on the first option, and I was left without any apparent way to undo my mistake and to go back to the "Publish code as wiki" scenario. Everytime I went back to the wiki screen I could only see the editor and no options to remove the wiki from the project.&lt;/p&gt;

&lt;p&gt;With a bit of research I was able to find a very simple solution for this problem, and &lt;a href="https://docs.microsoft.com/en-us/cli/azure"&gt;Azure CLI&lt;/a&gt; was again my best friend. &lt;/p&gt;

&lt;p&gt;Using this tool, and the respective &lt;a href="https://docs.microsoft.com/en-us/cli/azure/devops/extension?view=azure-cli-latest"&gt;DevOps extension&lt;/a&gt;, you can easily find the ID of that default repository using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; az devops wiki list &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"{repository-name}"&lt;/span&gt; &lt;span class="nt"&gt;--organization&lt;/span&gt; &lt;span class="s2"&gt;"https://dev.azure.com/{organization-name}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of that command will give you the details of the default repo that was created to host the wiki, including the necessary Id that you can now use to permanently remove that repository from your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az repos delete &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"{repository-name}"&lt;/span&gt; &lt;span class="nt"&gt;--organization&lt;/span&gt; &lt;span class="s2"&gt;"https://dev.azure.com/{organization-name}"&lt;/span&gt; &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;repository-id&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the above, you can now go back to Azure DevOps and to the wiki screen and you'll again be presented with the two options to choose from.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>devops</category>
      <category>azurecli</category>
    </item>
  </channel>
</rss>
