I am using these commands to create a test Azure Wiki page.
#Azure DevOps Login < Works OK
echo '$env:ado_documentation_api_key' | az devops login --org https://dev.azure.com/***
#Create Code Wiki < Works OK
$Wiki_id = az devops wiki create --name test --type codewiki --version master --repository Azure.Agents --mapped-path /Documentation --query id -o tsv
#Create Wiki Page < Doesn't work
az devops wiki page create --path 'Documentation' --wiki $Wiki_id --file-path ./wiki.md --encoding utf-8
Expected behaviour:
To upload a new wiki page in Azure DevOps.
Actual behaviour:
The versionType should be 'branch' and version cannot not be null
Parameter name: versionDescriptor
Any assistance to resolve this issue, would be appreciated.
Reproduce the same issue when use the same Rest API to create Wiki Page.
The cause of the issue is from the Azure DevOps CLI extension itself.
When you add the --debug argument in Azure DevOps CLI, you will see that the az devops wiki page create command is using the Rest API version 5.0.
Refer to this doc about Pages - Create Or Update Version 5.0 It doesn't support the parameters: versionType.
This parameter is available after Rest API version 5.1.
The root cause of the issue is that Azure DevOps CLI requires versionType parameter, but Azure DevOps CLI is using old version of Rest API which doesn't support the version type argument.
This is a known issue with Azure DevOps CLI creating wiki pages. Refer to this Feedback ticket: Create wiki page using CLI extension fails with error "The versionType should be 'branch' and version cannot not be null"
For a workaround, you can use Rest API to create the wiki page: Pages - Create Or Update
Here is a PowerShell example:
$content = [IO.File]::ReadAllText("wiki\file.md")
$data= #{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"
$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath/$WikiSubPagePath&api-version=6.0"
$Header = #{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = #{
Uri = $uri;
Headers = $Header;
Method = 'Put';
ContentType = "application/json";
body = $data;
}
Invoke-RestMethod #params
Related
I am running an azure pipeline to deploy applications to the cloud.
Before deploying I want to check if the current version deployed on the cloud is not same as the version the user wants to deploy.
I was looking into getting release name of the build which was deployed before.
I am using Azure devops git as my repository.
Is there any way I can get the desired information using the Azure Devops Rest API?
Thanks in advance.
I was looking into getting release name of the build which was deployed before. I am using Azure devops git as my repository.
We could use the REST API Releases - List with argument $top to get the latest release pipeline:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?definitionId={definitionId}&`$top={$top}&api-version=6.0
We could get the latest release pipeline Id:
$connectionToken="Your PAT Here"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$ReleasePipelineUrl = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?definitionId={definitionId}&`$top={$top}&api-version=6.0"
Write-Host "URL: $ReleasePipelineUrl"
$ReleasePipelineInfo = (Invoke-RestMethod -Uri $ReleasePipelineUrl -Method Get -UseDefaultCredential -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)})
$LatestReleaseId = $ReleasePipelineInfo.value.id | ConvertTo-Json -Depth 100
Write-Host "LatestReleaseId = $LatestReleaseId"
After getting the LatestReleaseId, we could use the REST API Releases - Get Release:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=6.0
to get the detailed info, like artifact name about the latest pipeline:
$connectionToken="Your PAT Here"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$ReleaseArtifactUrl = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/$($LatestReleaseId)?api-version=5.1"
Write-Host "URL: $ReleaseArtifactUrl"
$ReleaseArtifactInfo = (Invoke-RestMethod -Uri $ReleaseArtifactUrl -Method Get -UseDefaultCredential -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)})
$ReleaseArtifactName = $ReleaseArtifactInfo.artifacts.definitionReference.version.name | ConvertTo-Json -Depth 100
Write-Host "ReleaseArtifactName = $ReleaseArtifactName"
Now, we get the release name of the build which was deployed latest time.
To resolve your question, we could add a powershell task in your build pipeline to invoke above REST API to check the Release name.
And add another task to compare whether the release name is the same as the artifact name generated by this build, we could use REST API to get it Artifacts - Get Artifact. If they are different, call the REST API to trigger the release pipeline. If they are the same, do nothing.
Therefore, we can judge whether there is an update by the name or version of each artifact generated, but it seems difficult to do it if we want to directly compare the version of the app. Unless we throw out this information about the app when building our pipeline, and then use the REST API to get it, for example, store it in a file. In any case, these methods require a bit of familiarity with the REST API and hope to help you.
After migration from Confluence to Azure DevOps I can't delete or rename articles containing dots.
I already tried this api to delete an article , but it didn't work.
Error:
The wiki page operation failed with message : The page name cannot start or end with a "." and cannot contain the following characters /, \. Parameter name: pageName
You can try azure devops cli to see if this works.
To edit a wiki page, enter the az devops wiki page update command.
az devops wiki page update --path
--version
--wiki
To delete a wiki page, enter the az devops wiki page delete command.
az devops wiki page delete --path
--wiki
For details ,please refer to this document.
I have an SSIS project that uses the Azure Storage Connection Manager from SSIS Azure Feature Pack. When this connection is included in the project, the Azure Pipeline Build fails with the following message with a vs2017 hosted agent:
System.ArgumentException: Value does not fall within the expected
range. at
Microsoft.SqlServer.Dts.Runtime.Interop.ProjectInterop.ReferencePackage(Package
package, String packageLocation) at
Microsoft.SqlServer.Dts.Runtime.PackageItem.Load(IDTSEvents events) at
Microsoft.SqlServer.Dts.Runtime.PackageItem.get_Package() at
Microsoft.DataTransformationServices.Project.DataTransformationsProjectBuilder.IncrementalBuildThroughObj(IOutputWindow
outputWindow) at
Microsoft.DataTransformationServices.Project.DataTransformationsProjectBuilder.BuildIncremental(IOutputWindow
outputWindow)
When the Azure Storage Connection Manager is removed the the project, the Azure Pipeline Build is successful.
I have also tried 2019 hosted agent but it failed wit ha different error (Some errors occurred during migration. For more information, see the migration report).
Is the Azure Feature Pack for SSIS not installed on the hosted agents? I would like to resolve this without having to use self hosted or docker.
The capabilities of Microsoft-Hosted agents can be checked here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops
They don't have seem to include SSIS support. You can try to install those as part of the build definition. For example:
https://erwindekreuk.com/2019/02/azure-devops-and-azure-feature-pack-for-integration-services/
Thank you JukkaK. The solution you posted worked for me, with a slight change - i had to change all of the single quotes to double quotes - it was not recognizing the variable for the file correctly. Below is the final solution in my implementation:
Write-Information "Installing SSIS Azure Feature Pack 2017"
#Define Filename
$Filename = "SsisAzureFeaturePack_2017_x64.msi"
$Arguments="/qn"
Write-Host "Downloading " $Filename
#Define download link including filename and output directory with filename
Invoke-WebRequest -Uri "https://download.microsoft.com/download/E/E/0/EE0CB6A0-4105-
466D-A7CA-5E39FA9AB128/SsisAzureFeaturePack_2017_x64.msi" -OutFile
"$(Build.StagingDirectory)\$Filename"
Write-Host "Installing "$Filename
Invoke-Expression -Command "$(Build.StagingDirectory)\$Filename $Arguments"
Write-Host "Finished Installing " $Filename
I am trying to invoke rest api from within Azure DevOps build agent. For that I need bearertoken which I can get in my local machine with:
$accessToken = ((Get-AzContext).TokenCache.ReadItems() | Where { $_.TenantId -eq (Get-AzContext).Tenant } | Sort-Object -Property ExpiresOn -Descending)[0].AccessToken
However, on the build agent this never returns any tokens. Is there some other way I should try to get that token?
Have you enabled the 'Allow scripts to access the OAuth token' setting in the Agents settings?
This would be for builds and releases using the visual designer.
For YAML builds see the predefined variable documentation. There are notes about using the "System.AccessToken" variable in a script. Essentially, you must explicitly map System.AccessToken into the pipeline using a variable. You can do this at the step or task level:
steps:
- bash: echo This is a script that could use $SYSTEM_ACCESSTOKEN
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- powershell: Write-Host "This is a script that could use $env:SYSTEM_ACCESSTOKEN"
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
Thanks for the suggestions and ideas. Answer was too simple to figure it out. I ripped most of the oneliner and now it works by only using:
$accessToken = ((Get-AzContext).TokenCache.ReadItems()
I found a very strange problem here:
In Azure powershell, we can use
Start-AzureVM -ServiceName "mypc" -Name "mypc"
for both VM state= stop or stop(Deallocated).
But for Azure Mangement API
We can use start role only for VM state= stop
VM state=stop(deallocated) can't use that API..
How can I use REST API to start VM with State=Stop(deallocated)?
Thanks.
The Windows Azure PowerShell cmdlets use the Service Management REST API - but it uses an undocumented 2013-06-01 version. It is possible that this operation is available only in the undocumented version of the Service Management REST API.
You can see what the cmdlets actually do by using Fiddler to proxy the request - this gives you access to the operation invoked (URL) as well as the payload sent and received. Alternatively, you can look at the PowerShell cmdlets source which is available on GitHub.
POST https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roleinstances/<role-name>/Operations
**x-ms-version: 2013-06-01**
<StartRoleOperation xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><OperationType>StartRoleOperation</OperationType></StartRoleOperation>
public Task<ComputeLongRunningOperationResponse> StartVirtualMachineAsync(string subscriptionId, string name, string resource_group)
{
TokenCloudCredentials tokenCloudCredential = new TokenCloudCredentials(subscriptionId, token);
ComputeManagementClient computeManagementClient = new ComputeManagementClient(tokenCloudCredential);
return computeManagementClient.VirtualMachines.StartAsync(resource_group, name);
}