I have an Azure CLI task which references a PowerShell script (via build artifact) running az commands. Most of these commands work successfully, but when attempting to execute the following command:
az appconfig kv import --name $resourceName -s file --path appconfig.json --format json
I've noticed that the information was not present against the Azure resource and the log file has "File is not available".
I must be referencing the file incorrectly from the build artifact but if anyone could provide some clarity around this that would be great.
I must be referencing the file incorrectly from the build artifact
You can try to add $(System.ArtifactsDirectory) to the json file path. For example: --path $(System.ArtifactsDirectory)/appconfig.json.
System.ArtifactsDirectory: The directory to which artifacts are downloaded during deployment of a release. Example: C:\agent\_work\r1\a
For details ,please refer to predefined variables .
This can be a little tricky to figure out.
System.ArtifactsDirectory is the default variable that indicates the directory to which artifacts are downloaded during deployment of a release.
However, to use a default variable in your script, you must first replace the . in the default variable names with _. For example, to print the value of artifact variable System.ArtifactsDirectory in a PowerShell script, you would have to use $env:SYSTEM_ARTIFACTSDIRECTORY.
I have a similar setup and do it this way within my PowerShell script:
# Define the path to the file
$appSettingsFile="$env:SYSTEM_ARTIFACTSDIRECTORY\<rest_of_the_path>\appconfig.json"
# Pass it to the Azure CLI command
az appconfig kv import -n $appConfigName -s file --path $appSettingsFile --format json --separator . --yes
It is also helpful to view the current values of all variables to see what they contain before using them.
References:
Default variables - System
Using default variables
Related
I would like to move files that are available in the system working directory in the azure pipeline to the Kubernetes pod.
Method one (Kubectl cp command)
kubectl cp D:\a\r1\a\test-files\westus\test.txt /test-745f6564dd:/inetpub/wwwroot/
D:\a\r1\a\test-files\westus\test.txt -- my system working directory file location
(name-space)/test-745f6564dd:/inetpub/wwwroot/ -- kubernetes pod location
I have tried to use kubectl cp command but facing an error.
error: one of src or dest must be a local file specification
Method two command line tool in azure devops
Even i tried to use command line to copy files from one directory to another directory.
cd C:\inetpub\wwwroot>
copy C:\inetpub\wwwroot\west\test.txt C:\inetpub\wwwroot\
Once this task is executed in the azure pipeline, its throwing error.
he syntax of the command is incorrect.
Method three azure cli
I have tried to use azure cli and login into Kubernetes and tried to try one of the below codes. But not throwing any errors even file is not copied too.
az aks get-credentials --resource-group test --name test-dev
cd C:\inetpub\wwwroot
dir
copy C:\inetpub\wwwroot\west\test.txt C:\inetpub\wwwroot\
Is there any way do this operation.
For the first error:
error: one of src or dest must be a local file specification
Try to run the kubectl cp command from the same directory where your file is there and instead of giving the whole path try like below:
kubecto cp test.txt /test-745f6564dd:/inetpub/wwwroot/test.txt
I am looking to create and update some Azure Devops Wiki pages for my project using Az Cli from an Azure Pipeline job.
However, the required commands (examples below) all have a --file-path attribute which is described as the "Path of the file input if content is specified in the file".
az devops wiki page create --path 'my page' --wiki myprojectwiki --file-path a.txt
az devops wiki page update --path 'my page' --wiki myprojectwiki --file-path a.txt
Can anyone assist with examples of how this --file-path parameter can be set or passed, for example:
An input file with a remote URL, e.g. http://.... ?
An input file with an Azure Repo file path?
An input file stored in a shared folder with a UNC path?
Unfortunately, the basic "a.txt" example provided in the two code snippets from learn.microsoft.com (above) don't exactly provide any clarity.
You'll need to provide the full path to the file, e.g. C:\users\johndoe\desktop\a.txt. Then the suggested commands will work.
Is there an option to handle the next situation:
I have a pipeline and Copy Files task implemented in it, it is used to upload some static html file from git to blob. Everything works perfect. But sometimes I need this file to be changed in the blob storage (using hosted application tools). So, the question is: can I "detect" if my git file is older than target blob file and ignore this file for the copy task to leave it untouched. My initial idea was to use Azure file copy and use an "Optional Arguments" textbox. However, I couldn't find required option in the documentation. Does it allow such things? Or should this case be handled some other way?
I think you're looking for the isSourceNewer value for the --overwrite option.
--overwrite string Overwrite the conflicting files and blobs at the destination if this flag is set to true. (default true) Possible values include true, false, prompt, and ifSourceNewer.
More info: azcopy copy - Options
Agree with ickvdbosch. The isSourceNewer value for the --overwrite option could meet your requirements.
error: couldn't parse "ifSourceNewer" into a "OverwriteOption"
Based on my test, I could reproduce this issue in Azure file copy task.
It seems that the isSourceNewer value couldn't be set to Overwrite option in Azure File copy task.
Workaround: you could use PowerShell task to run the azcopy script to upload the files with --overwrite=ifSourceNewer
For example:
azcopy copy "filepath" "BlobURLwithSASToken" --overwrite=ifSourceNewer --recursive
For more detailed info, you could refer to this doc.
For the issue about the Azure File copy task, I suggest that you could submit a feedback ticket in the following link: Report task issues.
I need to use Build.Repository.Uri in a release pipeline. (to pass it to a PowerShell script)
In a buildpipeline:
Write-Host $(Build.Repository.Uri)
> 2019-07-15T08:30:51.8695425Z http://138.202.18.216:8070/Samples/Framework%20A/_git/Framework%20A
In a releasepipeline:
Write-Host $(Build.Repository.Uri)
> The name Build.Repository.Uri was not recognized as the name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if the path is correct (if included), and try again.
Why that inconsistency?
I also try Write-Host $(env:BUILD_REPOSITORY_URI) because of that: How to read directory path of the Artifact in Release pipeline in Azure DevOps? (I also don't understand the logic behind . to _)
Is there a way to get Build.Repository.Uri in a releasepipeline?
EDIT: Solution
"$env:SYSTEM_TASKDEFINITIONSURI$env:BUILD_PROJECTNAME/_git/$env:BUILD_REPOSITORY_NAME" -> http://136.202.18.216:8070/Samples/Framework A/_git/Framework A
If you set system.debug variable to true, you can find all predefined variables inside of the Job Initialize (Auftrag initialisieren) Report after a build.
If your project or repository name contains spaces, make sure that you replace them in your script with %20:
$Uri = $Uri.Replace(" ", "%20")
To access the Build URI in the Release Pipeline you need to use the release variable:
Release.Artifacts.{alias}.BuildURI
{alias} is the the alias of the artifact source you have in the release
If you accessing variables within PowerShell scripts you need to replace any dots with underscores i.e. $env:RELEASE_ARTIFACTS_{alias}_BUILDURI
Source: https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch
The variable Build.Repository.Uri is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task. When you add variable System.Debug with value true in the pipeline, the init job will log all the available environment variables, which includes the REPOSITORY_URI.
You can try with following variables:
Write-Host $env:BUILD_REPOSITORY_URI
Or
Write-Host $env:RELEASE_ARTIFACTS_{alias}_REPOSITORY_URI
Please note that the {alias} is the uppercase of the Artifact source alias.
Is the Folder Name available as an environment variable similar to JOB_NAME?
For a folder; JOB_NAME contains the full path including parent folders. I want the immediate parent folder as an environment variable.
I used:
FOLDER_NAME=${JOB_NAME%/*}
STAGE=${JOB_NAME##*/}
See http://www.tldp.org/LDP/abs/html/parameter-substitution.html
No such variable exists, but $(basename $(dirname $JOB_NAME)) would give you what you are asking for.
Using the suggestion of $(basename $(dirname $JOB_NAME)) combined with the Environment Script Plugin, you should be able to set such an environment variable by selecting Generate environment variables from script and then providing the Script Content of:
echo FOLDER_NAME=$(basename $(dirname $JOB_NAME))