Error with Command Line Script in Azure DevOps Pipeline - azure

I'm building my first pipeline using Power Platform Build Tools. I'm trying to export a Dynamics model driven app to a repo. I'm getting an error with in my Command Line Script. The following is the error log:
2021-01-21T08:48:04.6191345Z ##[section]Starting: Command Line Script
2021-01-21T08:48:04.6292483Z
==============================================================================
2021-01-21T08:48:04.6292831Z Task : Command line
2021-01-21T08:48:04.6293131Z Description : Run a command line script using Bash on Linux and macOS
and cmd.exe on Windows
2021-01-21T08:48:04.6293422Z Version : 2.178.0
2021-01-21T08:48:04.6293630Z Author : Microsoft Corporation
2021-01-21T08:48:04.6293952Z Help :
https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2021-01-21T08:48:04.6294293Z
==============================================================================
2021-01-21T08:48:05.7216764Z error: pathspec 'master' did not match any file(s) known to git
2021-01-21T08:48:05.7217182Z Generating script.
2021-01-21T08:48:05.7217463Z ========================== Starting Command Output
===========================
2021-01-21T08:48:05.7217952Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL
"D:\a\_temp\93c0ac5e-da28-4265-b4d0-4326b5f38209.cmd""
2021-01-21T08:48:05.7218457Z commit all changes
2021-01-21T08:48:05.7218642Z push code to new repo
2021-01-21T08:48:05.7226781Z fatal: pathspec '-' did not match any files
2021-01-21T08:48:05.7227220Z error: pathspec 'export"' did not match any file(s) known to git
2021-01-21T08:48:06.2395991Z git: 'bearer' is not a git command. See 'git --help'.
2021-01-21T08:48:06.2983259Z ##[error]Cmd.exe exited with code '1'.
2021-01-21T08:48:06.3323471Z ##[section]Finishing: Command Line Script
Based on this output, I don't know what is missing.

According to your screenshots, your default branch is "main", not "master".
The master did not match any branches known to git, so the task failed.
In addition, you need to use origin/{branch} instead of {branch}. As the branch is a remote branch.

Error with Command Line Script in Azure DevOps Pipeline
This may be because your git command has wrong syntax.
According to the image you provided, we could to know the git command line you used is:
This is not the correct syntax to add all files, that also the reason why you get the error:
fatal: pathspec '-' did not match any files
If I use the same syntax git add —— all, I will get the same error message.
To resolve this error, please try to use following correct syntax:
git add --all
Besides, we could not use the AUTHORIZATION:BEARER with $(system.AccessToken), you need to use Authorization: Basic with Base64-encode:
Please check this thread for some more details.
That the reason why you get the error git: 'bearer' is not a git command..
To resolve this issue, you could use git command line with PAT directly to push the files:
git push https://<Your PAT>#dev.azure.com/<YourOrganization>/<YourProject>/_git/MyTestProject HEAD:master
In addition, what Jane said is another issue.

Related

Unable to trigger shell script from azure repo through pipeline

I have deploy.sh file in my azure repository and i need to execute this deploy.sh file from azure pipeline.
Here is the steps that i defined in pipeline. I tried two ways to do it through cmd and bash, both are not picking the right location of deploy.sh file
Here is the error i am getting:
This is the error from CMD, but CMD shows green even though path is not correct
This is the error for bash
Question
How to correct the path and do successful execution of deploy.sh?
You should never hard code the path of the pipeline run. Instead you should use the predefined variables that will automatically pick the build ID and also path. For your case you will need the
$(Pipeline.Workspace)/s/Orchestration/dev/deploy.sh
If you have multiple repositories checkout you should also use the name of the repository like
$(Pipeline.Workspace)/s/dotnetpipeline/Orchestration/dev/deploy.sh
$(Pipeline.Workspace)/s should be also replaced by $(Build.SourcesDirectory)
The predefined variables should follow the $(var) notation on the .YML file
This solved my issue
- task: CmdLine#2
inputs:
script: |
echo Write your commands here
cd $(Build.Repository.Name)/Orchestration/dev/
chmod +x deploy.sh
./deploy.sh
echo deploy.sh execution completed

Gitlab job failure: Cannot overwrite variable Host because it is read-only or constant

Hi people of the internet.
Basically I am unable to run even the simplest job and I keep getting the same error no matter what I put in the .gitlab-ci.yml file. See example below:
Here is the .gitlab-ci.yml file:
stages:
- test
job1:
stage: test
tags:
- testing
script:
- echo "Hello world!"
Here is the output ("?" corresponds to intentionally blacked out information):
Running with gitlab-runner 14.10.0 (c6bb62f6)
on runner_test ????????
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on LAPTOP-????????...
Getting source from Git repository
00:01
WriteError:
Line |
219 | $HOST="[MASKED]"
| ~~~~~~~~~~~~~~~~~~~~~~
| Cannot overwrite variable Host because it is read-only or constant.
ERROR: Job failed: exit status 1
I know that $HOST is a reserved variable in powershell but I don't see the link between the error and the code. It may have something to do with the configuration of the runner on Windows. Has anyone encountered this error on Gitlab before? Or any suggestions on how to debug?
Here are the steps that I took to install the runner on Gitlab for Windows (see https://docs.gitlab.com/runner/install/windows.html):
Create a folder somewhere in the system: C:\GitLab-Runner.
Download the binary for 64-bit and put it into the folder (see https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe).
Run prompt as an administrator
Run the following command:
cd C:\GitLab-Runner
gitlab-runner.exe register
Enter your GitLab instance URL (see Gitlab > Settings > CI/CD > Runners > Specific runners)
Enter the token to register the runner (see Gitlab > Settings > CI/CD > Runners > Specific runners)
Enter a description for the runner: runner_test for instance
Enter the tags associated with the runner, separated by commas: testing, windows for instance
Provide the runner executor: shell
Install GitLab Runner as a service and start it
cd C:\GitLab-Runner
gitlab-runner.exe install
gitlab-runner.exe start
I also had to install the latest version of pwsh in Windows (see gitlab-runner: prepare environment failed to start process pwsh in windows):
Run prompt as an administrator
Install the newer pwsh.exe:
winget install Microsoft.PowerShell
Restart the runner
cd C:\GitLab-Runner
gitlab-runner.exe restart
This issue was due to my choice of shell for some reason. A Gitlab runner can choose a shell among the following: bash, sh, powershell, pwsh, and cmd (the last one being deprecated now).
As I stated above I had been using pwsh. So, I went after the config.toml file inside of the C:\GitLab-Runner directory to manually make the change from pwsh to powershell.
...
[[runners]]
name = "runner_test"
executor = "shell"
shell = "powershell"
...
I then restarted the runner and got the job to complete properly:
cd C:\GitLab-Runner
gitlab-runner restart
I still get the error (more like a warning now) but it does not prevent the job from finishing anymore. If anyone has a better answer with a proper explanation I would gladly accept it as the answer to this question.
Note that pwsh to powershell are both powershell scripts (see https://docs.gitlab.com/runner/shells/index.html):
powershell Fully Supported PowerShell script. All commands are executed in PowerShell Desktop context. In GitLab Runner 12.0-13.12, this is the default when registering a new runner.
pwsh Fully Supported PowerShell script. All commands are executed in PowerShell Core context. In GitLab Runner 14.0 and later, this is the default when registering a new runner.

How to Automatically upload a file to Azure DevOps repository through a release pipeline CMD task

I have created a release pipeline in Azure devops to generate the .dacpac file using CMD task in release pipeline. The .dacpac file is getting generated successfully when I am giving \tf: path as $(Agent.HomeDirectory). I want to give path of the folder in my repository where I would like to save the .dacpac file.
Below is the command which I tried to store the file on (Agent.HomeDirectory) and it runs fine.
C:\Program Files (x86)\Microsoft SQL Server\150\DAC\bin>sqlpackages.exe /Action:Extract /ssn:tcp:,1433 /sdn: /su: /sp: /tf:$(Agnet.HomeDirectory)/test.dacpac /p:Storage=File
Please guide me how we can store the file to repository folder from command line.
Thanks,
Sachin
Please refer to the following steps:
I created a release pipeline and added this repo: testproject, branch: test
Add CMD task, the script is as follows:
cd D:\a\r1\a_testproject
cd . > 001.txt // I create a test txt here. Please copy the file you need to the path. Or you can to use git to clone a repo in the path you want.
git config --global user.email "xxxx#mail.com"
git config --global user.name "xxxx"
git status
git add -A
git status
git commit -m "Latest updated"
git show-ref
git push -u origin HEAD:test //if the push step show the error: src refspec xxxx does not match any. please check the log and choose a rignt head
Allow scripts to access the OAuth token
set permission of the account {projectname} Build Service (orgname)
For more info ,please refer Copy file from CI Pipeline to Azure Devops Repository and How to add/update files in git repository from Azure DevOps Pipeline Dynamics 365 CE.

Unable to add web part to catalog pipeline azure - access denied

I have created a pipeline to bundle and add a webpart to the app catalog. I am getting this access error below. Any ideas?
2019-10-17T16:28:44.6630984Z ##[section]Starting: add package to catalog
2019-10-17T16:28:44.6740356Z ==============================================================================
2019-10-17T16:28:44.6740433Z Task : Command line
2019-10-17T16:28:44.6740486Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2019-10-17T16:28:44.6740546Z Version : 2.151.2
2019-10-17T16:28:44.6740587Z Author : Microsoft Corporation
2019-10-17T16:28:44.6740630Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2019-10-17T16:28:44.6740689Z ==============================================================================
2019-10-17T16:28:45.4965469Z Generating script.
2019-10-17T16:28:45.5061921Z Script contents:
2019-10-17T16:28:45.5070670Z o365 spo app add -p d:\a\r1\a/_ABFI-CI/drop/sharepoint/solution/json-feed.sppkg --overwrite
2019-10-17T16:28:45.5392405Z ========================== Starting Command Output ===========================
2019-10-17T16:28:45.5641516Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\6ca1b36f-40ef-444b-ae13-9e5ba3ba5d98.cmd""
2019-10-17T16:28:49.1097084Z Error: Access denied. You do not have permission to perform this action or access t**strong text**his resource.
2019-10-17T16:28:49.2305193Z ##[error]Cmd.exe exited with code '1'.
2019-10-17T16:28:49.2676400Z ##[section]Finishing: add package to catalog
I just needed to be added as an admin to the site!

source parameter not specified cake

using azure devops to build a pipeline. pipeline uses cake scripts to build and publish. facing issue with publish package. below is the diagnostic of publish of nu get step.
2019-09-16T10:00:32.8150943Z NuGet
2019-09-16T10:00:32.8151140Z ========================================
2019-09-16T10:00:32.8151688Z Executing task: NuGet
2019-09-16T10:00:32.8195231Z PushNuGet
2019-09-16T10:00:32.8283167Z Pushing NuGet file C:/__w/2/a/build/A.SDK.TestLibrary/nuget/A.TestLibrary.SDK.1.4.2-abranch-15524.nupkg
2019-09-16T10:00:32.8331210Z No Source property has been set. Depending on your configuration, this may cause problems.
2019-09-16T10:00:32.8620102Z Executing: "C:/__w/2/a/build/tools/NuGet.exe" push "C:/__w/2/a/build/A.SDK.TestLibrary/nuget/A.TestLibrary.SDK.1.4.2-abranch-15524.nupkg" -NonInteractive
2019-09-16T10:00:33.3578097Z Source parameter was not specified.
2019-09-16T10:00:33.3864258Z An error occurred when executing task 'NuGet'.
2019-09-16T10:00:33.3996249Z Error: System.AggregateException: One or more errors occurred. ---> Cake.Core.CakeException: NuGet: Process returned an error (exit code 1).
source parameter not specified cake
Just like the error message shows,
Source parameter was not specified
And your nuget command line is:
"C:/__w/2/a/build/tools/NuGet.exe" push "C:/__w/2/a/build/A.SDK.TestLibrary/nuget/A.TestLibrary.SDK.1.4.2-abranch-15524.nupkg"
Indeed, it does not specify the source of the push command.
To resolve this issue, you should specify the source in that command:
nuget.exe push "YourPackageHere" -source "xxxx"
Check the document push command (NuGet CLI) for some more details.
Hope this helps.

Resources