为什么 fastlane 工作目录与我设置的不同

why fastlane working directory different than what I set

使用 Jenkins 的快速通道。 Jenkins 将 pwd 设置为一个目录,我们称之为 directory1,它具有标准的 Fastfile 和 fastlane 子文件夹,如下所示:

MacBook-Pro:directory1 user$ tree

├── fastlane
│   ├── Deliverfile
│   
├── Fastfile

Jenkins 然后从该目录执行 fastlane。使用需要路径的快速通道操作时,如果我使用假定工作目录为 directory1 的路径,一切正常。但我不明白的是,为什么当我从 fastlane 查询密码时,无论是使用 sh 操作还是直接 Ruby Dir.pwd,都给我值 /MacBook-Pro/directory1/fastlane 而不是比我设置的工作目录/MacBook-Pro/directory1。关于 fastlane 在这里对目录所做的事情,我错过了什么?

Fastlane 在使用 sh() 运行 shell 命令时有一些奇怪的目录行为。解决方法是更改​​目录,或者在您执行 运行 shell 等 pwd 命令时在路径前加上 ..

根据 official docs:

...every action and every plugin's code runs in the root of the project, while all user code from the Fastfile runs inside the ./fastlane directory. This is important to consider when migrating existing code from your Fastfile into your own action or plugin. To change the directory manually you can use standard Ruby blocks:

Dir.chdir("..") do # code here runs in the parent directory end

This behavior isn't great, and has been like this since the very early days of fastlane. As much as we'd like to change it, there is no good way to do so, without breaking thousands of production setups, so we decided to keep it as is for now.