Home > Net >  Azure DevOps Pipeline- push file to repo in one job and retrieve it in another job
Azure DevOps Pipeline- push file to repo in one job and retrieve it in another job

Time:11-30

I am currently designing a pipeline in Azure Devops. I have designed two seperate jobs.

First job will create a file, modify it and upload it to the repo hosted in Azure Devops (I have already figured out how to do that, and it works fine). The second job will utilize that file again. (Obviously, there is a reason behind why I need two separate jobs)

Indeed, after executing the first job, the file is pushed into the repo and I can see it in my repo in DevOps. However, for the second job, even though it has checked out the current repo and pulled all the files, but weirdly it does not contain the file I have just pushed to repo (I have verified using ls -a)

Is it because the pipeline in Azure will only pull the same branch for all jobs (regardless commits has been made to the repo during execution)? How do I solve this issue ? (i.e how can I let the job always pull the latest branch ?)


UPDATE:

I just realized that the azure pipeline automatically pulls the same ref for all the jobs even if there are new commits made. I think this is the reason why my other jobs are not able to retrieve the newly commit file.

However, the checkout step was automatically added by the pipeline as part of the execution. I have no idea how to modify the commands used in that step. I don't have such advanced git knowledge, neither to let git always retrieve the latest ref.

Some help would be appreciated

CodePudding user response:

I think you can get it to work by doing a simple bash task that would look like this:

- bash: |
      git fetch --all
      git pull
      *and then the stuff you want to do*
  displayName: Get Latest Branch Version

I have to say I'm not a huge fan of what you are trying to do: for me the ref on which a pipeline is running is very important, if the pipeline fails or if you need to debug it well you know exactly what ref to checkout. Also, I can see a pretty obvious infinite loop of triggers (if you have a trigger on the branch, when the file is commited its going to trigger another pipeline etc etc). But I don't have the full story so I imagine you have reasons to do it like this.

If I have jobs that need to do work on a common file I would've gone for somehting like this ? https://stackoverflow.com/questions/58626768/how-to-share-files-between-jobs#:~:text=Addtion: For sharing files between,published by the previous job.

Anyway, hope my answer was somewhat useful

  • Related