简体   繁体   English

Azure DevOps Pipeline- 在一个作业中将文件推送到 repo 并在另一个作业中检索它

[英]Azure DevOps Pipeline- push file to repo in one job and retrieve it in another job

I am currently designing a pipeline in Azure Devops.我目前正在 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).第一份工作将创建一个文件,对其进行修改并将其上传到 Azure Devops 中托管的存储库(我已经想出了如何做到这一点,并且工作正常)。 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.事实上,在执行第一个作业后,文件被推送到存储库中,我可以在 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 )然而,对于第二份工作,即使它已经检查了当前的回购并提取了所有文件,但奇怪的是它不包含我刚刚推送到回购的文件(我已经使用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)?是因为 Azure 中的管道只会为所有作业提取相同的分支(无论在执行期间是否已对回购进行提交)? How do I solve this issue?我该如何解决这个问题? (ie 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.我刚刚意识到 azure 管道会自动为所有作业提取相同的引用,即使有新的提交也是如此。 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.我没有这么高级的 git 知识,也不想让 git 总是检索最新的参考。

Some help would be appreciated一些帮助将不胜感激

I think you can get it to work by doing a simple bash task that would look like this:我认为您可以通过执行如下所示的简单 bash 任务来使其工作:

- 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.我不得不说我不是你正在尝试做的事情的忠实粉丝:对我来说,运行管道的 ref 非常重要,如果管道失败或者你需要很好地调试它,你确切地知道 ref结帐。 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%3A%20For%20sharing%20files%20between,published%20by%20the%20previous%20job . https://stackoverflow.com/questions/58626768/how-to-share-files-between-jobs#:~:text=Addtion%3A%20For%20sharing%20files%20between,published%20by%20the%20previous%20job .

Anyway, hope my answer was somewhat useful无论如何,希望我的回答有点用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM