Getting 404 Not found Error when running in Devops Pipeline

Copper Contributor

Hi Team,

 

we are using Azure Devops and we have configure to use self hosted agent. The reason we need to talk to our internal Network

 

I have a script like below

$URL= 'XXX
$output = Invoke-WebRequest -Uri $URL -UseBasicParsing -Method GET -ContentType "application/json" -ErrorAction silentlycontinue
# Gather password from Content property & convert from JSON
$x = $output.Content | ConvertFrom-Json
$PAPassword = $x.Content 
# Secure the password
$SecuredPAPassword = ConvertTo-SecureString $PAMPassword -AsPlainText -Force

Every tine I run it from the Pipeline, i get the below error 

The remote server returned an error: (404) Not Found.

when I run it from the Server where my self hosted agent is running it works successfully.
Why I cant run it from the Pipeline Since pipeline is using the same self hosted agent?

 

Can you Please help me on this?

 

Thanks,

Sujith.

4 Replies
It sounds like the script is trying to access a specific URL and is returning a 404 error when run from the pipeline, but works when run from the server where the self-hosted agent is located.

This could be caused by a number of things, such as:

The URL being accessed is incorrect or no longer valid
The server hosting the URL is not accessible from the pipeline's location
The script may not have the necessary permissions or credentials to access the URL when run from the pipeline
The script is run in different environment or context when run from pipeline, that could cause different behavior
You should check the URL to ensure that it is correct, check if the server hosting the URL is accessible from the pipeline, and ensure that the script has the necessary permissions and credentials to access the URL when run from the pipeline.

It may also be helpful to check if there are any differences in the environment or context when the script is run from the pipeline versus when it is run from the server.

@varunmittal Thanks for replying. 

 Checked the url and not using any environment variables. 

 

I Want to understand when you say server is not accessible from the pipeline. 

 

My understanding is like when i create the self hosted agent the pipeline is running on that server not on the devops. So if my scripts from self hosted agent server it should also run from pipeline right?

 

Pleas correct my understanding. 

Yes, your understanding is mostly correct. When you use a self-hosted agent, the pipeline runs on the same machine as the agent, which means that the pipeline has access to the same resources and environment as the agent.

However, there can be some differences between the pipeline and the agent, for example, the pipeline may be running in a different context or environment, or the pipeline may be running with different permissions or credentials.

Also, there could be some network/firewall restrictions that only allow the self-hosted agent to access the server but not the pipeline.

In your case, since the script works when you run it from the self-hosted agent, but it doesn't work when you run it from the pipeline, it's likely that the pipeline is running in a different context or environment and is unable to access the server, or that the pipeline is running with different permissions or credentials.

It's also possible that the script is not running as expected, as there could be some logic or syntax errors in the script that are causing it to fail.

I recommend checking the pipeline's configuration and environment to see if there are any differences between the pipeline and the agent, and to also check the script again for any errors or logical issues.
Thanks Varun.
Can you please let me know how can I jeck the pipeline configuration and environment?