Forum Discussion

TrapMusicJunkie's avatar
TrapMusicJunkie
Copper Contributor
Nov 15, 2023

How to push git repo to Azure Repos with Windows scheduled task?

Hi,

I have created a git repo on my on-prem server where I keep all my scripts. I would like to push this repo to Azure Repos via Scheduled Task in Windows and I can't figure out what am I doing wrong here.

My bash script looks as follows:

 

#!/bin/sh
(
cd E:\Git\Scripts
git add :/*.ps1
git commit -m "Commit message"
git push origin main
) 2>&1 | tee -a log.log

 

It works when executed manually but it does not work when executed via Windows Scheduled Task. Task was configured according to the article below with the difference that I use service account and run the task whether user is logged on or not:

https://medium.com/@psicliffs/how-to-automate-your-git-workflow-97cbaae596a8

 

I assume that it has to be something with passing through the credentials? Log is not being created  due to fact that script is stuck on "git push origin main" so I need to end it manually.

 

What is the best practice here?

Any advise would be much appreciated.

Regards,

Marcin

1 Reply

  • TrapMusicJunkie's avatar
    TrapMusicJunkie
    Copper Contributor

    Figured it out by myself. The key here was to use SSH authentication as described in the following article:

     

    https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops

     

    + had to change HTTPS to SSH as described here:

     

    https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops#q-how-can-i-start-using-ssh-in-a-repository-where-im-currently-using-https

Resources