I get these errors whenever i tried running my pipelines on my created agent ,lets say agent_test.
When I run pipelines for first time it works and if retried to run after that, same issues occur.
##[warning]'git config --get remote.origin.url' failed with exit code: 1, output: ''
##[error]One or several exceptions have been occurred.
##[error]System.UnauthorizedAccessException: Access to the path '/home/ubuntu/projectfile/myagent/_work/1/s/.next/cache/images/Nn1+Lvq9fpQugwxAHfYtWM8Fp0OWmIqb38i9HtcZ67Q=/60.1698820786123.R-Lptnv+qGQlQiip-n7JqnPeS4MDNx4NR4C9HBtCcNk=.webp' is denied.
---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
Before Build script, it gives error and stop running, the stop process name is "Checkout project-file@development to s"
My YML Script is :
trigger:
- development
pool:
name: 'projectfile'
stages:
- stage: SetPermissions
jobs:
- job: SetPermissions
displayName: 'Set Permissions'
steps:
- script: |
echo "Cleaning the repository..."
git clean -ff # Clean the repository to avoid permission issues
git reset --hard HEAD
echo "Setting permissions for the working directory..."
chown -R ubuntu:ubuntu $(System.DefaultWorkingDirectory)
chmod -R u+rw $(System.DefaultWorkingDirectory)
displayName: 'Set Permissions'
continueOnError: true
- stage: BuildAndDeploy
jobs:
- job: Build
displayName: 'Build'
steps:
- script: |
echo "Current working directory is: $(System.DefaultWorkingDirectory)"
echo "Install npm"
npm install
pwd
echo "Building the project..."
npm run build
echo "Installing pm2..."
npm install pm2
displayName: 'Npm install and Build'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(System.DefaultWorkingDirectory)'
artifact: 'userside_dev_artifact'
displayName: 'Publish Build Artifacts'
- script: |
echo "Deploying the project..."
pwd
# Check if PM2 connection is already established
if ! pm2 list | grep -q "projectfile"; then
echo "PM2 process not found. Running 'npm run pm2'..."
npm run pm2
else
echo "PM2 process is already running. Skipping 'npm run pm2'."
fi
pm2 restart all
echo "Deployment successful!"
displayName: 'Deploy'
workingDirectory: $(System.DefaultWorkingDirectory)
Weird things is, when i use chown -R ubuntu:ubuntu _work
and chmod -R u+rw _work
then pipeline run successfully and again if pipeline tried to run for second times, then it gives same above error. I tried different way, but still this issue has not been resolve. Provide me the solution to fix.
Note that : The above script is for user side which is build in next and same issue arise in admin panel build on react, but the issue doesnt arise in backend which is build in nodejs.
2
Answers
The issue has been fixed. By default azure dont allow root access neither sudo command.so what i did is :
In config.js, ADD THIS COMMAND
Similarly, In run.sh, add same command using nano editor or any editor:
and then we can do,
So, by this way we can provide root access to all the directory in azure devops
The error indicates the account(pipeline) doesn’t have permission on the file:
It could happen when the file or folder is being used by another process or application, or it’s read-only, hidden, encryted.
Probably you can firstly try to define a workspace clean schema under the job and choose the resources to clean up(eg: all).
If it’s unable to clean up the working directory and the error persists, you could need to check how the
.next/cache/images/N...webapp
generated in your workspace:Manually delete the files in local agent, run the pipeline and check if it will generate the files.
If not, these files should be generated by other process.
If yes, check your npm build steps. Could add two
chmod -R
commands after the npm build steps, so that it could have the permission for next build.