rfennell / AzurePipelines

A single Repo to contain the source for ALL my Azure DevOps Build/Release Extensions. The packages can be found in the Azure DevOps Marketplace
https://marketplace.visualstudio.com/search?term=fenn&target=VSTS&sortBy=Relevance
MIT License
343 stars 431 forks source link

Publish to Azure DevOps Wiki fails with Error: spawn git ENOENT #738

Closed ipavlovi closed 4 years ago

ipavlovi commented 4 years ago

Release notes are successful generated but in the next step publish to Azure DevOps Wiki fails with following error:

Error: Error: spawn git ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Error: Error: spawn git ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

tasklog_18.log

YAML Definition

steps:
- task: richardfennellBM.BM-VSTS-WIKIUpdater-Tasks.WikiFolderUpdaterTask.WikiFolderUpdaterTask@1
  displayName: 'Upload Release Notes to Technical Docs Wiki'
  inputs:
    repo: 'dev.azure.com/********/********/_git/TechnicalDocs.wiki'
    targetFolder: 'Environments\$(Release.EnvironmentName)\Releases\'
    sourceFolder: '$(Agent.TempDirectory)'
    Filter: '**/$(Release.ReleaseName)*.md'
    message: 'Auto-generated release notes for $(Release.ReleaseName) attempt $(Release.AttemptNumber)'
    gitname: '$(Release.RequestedFor)'
    gitemail: '$(Release.RequestedForEmail)'
    useAgentToken: false
    user: ******
    password: '$(PAT)'
    injectExtraHeader: false

I am getting the same outcome no matter I am using username and PAT, OAUTH token, or if credentials are passed via Header.

Agent Info

I have successfully tested the same task group using both azure-hosted and self-hosted agents with out any problems using OAUTH token. All release notes were successful published to the same git repo.

Once tests were all good I have added the same taskgroup to stages for our production environments.

Self-hosted agents on both test and production environments are configured to run under local admin account as windows service.

PAT issued for agents have full access to Azure DevOps.

Other info

rfennell commented 4 years ago

Sounds like you have tried everything I can think of. But, interestingly I had a similar issue myself yesterday

We tried everything we could think of, with no luck finding a real solution.

In the end, and it was a work around, what we did was to add a separate agent stage to the pipeline stage to do the release generation and wiki upload and got this to be run by a hosted agent. Would this work for you?

But this is a workaround but not a solution.

This task uses Simple-Git to do the upload, the task just wrappers this. The only way I can think of to move this forward is to do some local testing of Simple-Git a failing agent. Unfortunately, I don't have access to such an agent.

rfennell commented 4 years ago

Oh, sorry forgot to say there is one thing extra to try switch on the inject header option to true. This can help if proxies are in the way. It was added to fix an issue for on premises TFS setups, but it is worth a try

ipavlovi commented 4 years ago

Look like there is a work around the Git, at least if content should be published to AzureDevops Wiki

I can push new page to Wiki using PS and DevOps API but that is exactly what I wanted to avoid by using WIKIUpdater task.

I will keep on trying to find solution for the original problem

ipavlovi commented 4 years ago

I have tried Inject Header option but it failed with the same error message

ipavlovi commented 4 years ago

I think I have found the cause of the problem

Environment PATH variable had C:\Program Files\Git\cmd\ entry but C:\Program Files\Git\ was missing.

After Adding 'C:\Program Files\Git\' to the path and restarting agent service deployment was successful.

I am not 100% sure yet. Let me check it on another environment as well before closing this issue

ipavlovi commented 4 years ago

I was wrong.

The correct solution is to add C:\agent\externals\git\cmd to the Environment Path on agent machine. Previous solution will work only if Git is installed separately.

It seems that simple-git is sending git commands to console and console cannot resolve path to git.exe because it is not in the environment path.

rfennell commented 4 years ago

Thanks for the excellent analysis. I will add it to the wiki notes in a troubleshooting section

rfennell commented 4 years ago

New troubleshooting notes in WIKI with 1.12.3

innonav-dev commented 3 years ago

I was wrong.

The correct solution is to add C:\agent\externals\git\cmd to the Environment Path on agent machine. Previous solution will work only if Git is installed separately.

It seems that simple-git is sending git commands to console and console cannot resolve path to git.exe because it is not in the environment path.

We have the exact same problem here. Git is missing in the enviroment path variable. Can someone tell me, how I can add the Git-Path to the agent path variable?

rfennell commented 3 years ago

I assume you are using the hosted agents, as if it is private agent you can just update the path in the standard manner via the control panel for all users.

If it is hosted agent, then you need to make the change at runtime. The path is only an environmental variable, so you could try the process outlined here

innonav-dev commented 3 years ago

No, we are using private agents. I assume we are talking about the System capabilities of the agent, right? When I navigate to our Agent pools and then check agents capabilities, the Path variable doesn't contain a path to the git directory. And I can't update any variable in this control panel, since everything is locked. Am I trying to fix it in the wrong place?

rfennell commented 3 years ago

You can use the Windows UI to edit the path for all users

  1. Right click 'My Computer' and select 'Properties'.
  2. Click 'Advanced System Settings' link.
  3. Click 'Advanced' tab.
  4. Click 'Environment Variables...' button.

You can set the path here for all users on that machine

innonav-dev commented 3 years ago

So I was completely wrong :D Works like a charm now. Thank you.

phil-w commented 2 years ago

In case it helps anyone, I had this in a pipeline when using an Ubuntu VM, and the easiest fix was to switch to windows-latest, because that latter has the path to GIT already set up.

ddprince-pro commented 1 year ago

Maybe I'm not commenting in the right issue, but I'm also facing the same problem, but under an Ubuntu Hosted Agent. Any plan to make this task work on Linux? I know using the image windows-latest is the workaround, but we're trying to exclusively use linux machines inside our build agents to reduce the overall execution time.

rfennell commented 1 year ago

@ddprince-yaksa you have a new issue it is best to start a new discussion or issue with details of your problem.

This thread was about the WIKI Updater, this already support Windows, Linux and Max agents - but this that the task you are using?

ddprince-pro commented 1 year ago

@rfennell yes this is the task we're using. I'm having the issue described here under an Ubuntu agent. I can open a new issue if you want!

rfennell commented 1 year ago

So your problem is that the task cannot fine the instance of the Git command line tool?

I assume this is on an on premise Ubuntu agent, as I have tested this task with the Microsoft hosted Ubuntu agents. If that is the case, the fix is the same a Windows, make sure Git is installed on the agent and it is in the path

If that does not sort it, might be best to log a new issues with a details debug log (run with the variable system.debug=true set)

ddprince-pro commented 1 year ago

@rfennell this is not an on premise agent, we're using the Microsoft Hosted Agent. I'm currently getting the details and I can get back to you. Which information from the debug output would you like to see?

rfennell commented 1 year ago

The whole debug output for the task, the following is what I expect to see for a Ubuntu agent

##[debug]updateOrderFile=true
##[debug]orderFilePath=undefined
##[debug]injecttoc=False
Variable: Repo [dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki]
Variable: Filename [TestPageWithCreds-10703.md]
Variable: Contents [Header
---
**Build Number**: 10703`n**Build Trigger PR Number**: `n`n# Global list of WI (0)`n`n# Global list of CS (1)`n### Associated commits  (only shown if CS) `n* ** ID6b7059ed94faa2e0105fe4ad9b4784bbb7ff472d**`n  -  **Message:** Documentation update (#1472)`n  -  **Commited by:** rfennell`n
---
Footer]
Variable: Commit Message [Update from Release - $(Release.ReleaseName) with Creds]
Variable: Git Username [builduser]
Variable: Git Email [build@demo]
Variable: Use Agent Token [false]
Variable: Replace File [true]
Variable: Append to File [true]
Variable: Username [richardfennell]
Variable: Password [*****]
Variable: LocalPath [D:\a\1\s\azurerepowithcreds]
Variable: Data Is File [false]
Variable: SourceFile [undefined]
Variable: Tag Repo [false]
Variable: Tag [undefined]
Variable: Branch [undefined]
Variable: InjectExtraHeader [false]
Variable: SslBackend [undefined]
Variable: Retries [5]
Variable: trimLeadingSpecialChar [false]
Variable: fixLineFeeds [true]
Variable: fixSpaces [false]
Variable: insertLinefeed [false]
Variable: updateOrderFile [true]
Variable: prependEntryToOrderFile [false]
Variable: orderFilePath [undefined]
Variable: injecttoc [false]
The provided repo URL is dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki
The protocol is https
The provided repo URL is dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki
Trimmed the URL to dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki
URL used https://richardfennell:***@dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki
Cleaned D:\a\1\s\azurerepowithcreds
Cloned dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki to D:\a\1\s\azurerepowithcreds
Set GIT values in D:\a\1\s\azurerepowithcreds
No sub-directory passed change to D:\a\1\s\azurerepowithcreds
Pull in case of post clone updates from other users
Working file name is TestPageWithCreds-10703.md
Created the 'TestPageWithCreds-10703.md' in 'D:\a\1\s\azurerepowithcreds' - fixing line-endings
Added TestPageWithCreds-10703.md to repo D:\a\1\s\azurerepowithcreds
Using the file - D:\a\1\s\azurerepowithcreds/.order
Attempting to updating the existing .order file
Appending entry to the .order file
Added .order file to repo D:\a\1\s\azurerepowithcreds
##[debug]Committing the changes with the message: Update from Release - $(Release.ReleaseName) with Creds
Committed file "D:\a\1\s\azurerepowithcreds" with message "Update from Release - $(Release.ReleaseName) with Creds" as SHA ead54bbd8764e79031ef6dedc645bbfcfde25d9e
Attempt 1 - Push to dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki
Push completed
Finishing: Git based WIKI Updater - Azure DevOps with Creds update .order file
ddprince-pro commented 1 year ago

@rfennell please see attached. 93.txt

I confirm the following agent is used for the task: Pool: Azure Pipelines Image: ubuntu-latest Agent: Hosted Agent

rfennell commented 1 year ago

@ddprince-yaksa this is getting too complex to handle in a side chat - now being tracked in #1473