Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why fastlane working directory different than what I set

Using fastlane from Jenkins. Jenkins sets the pwd to a directory, lets call it directory1, that has the standard Fastfile and fastlane subfolders like this:

MacBook-Pro:directory1 user$ tree

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

Jenkins then executes fastlane from that directory. When using fastlane actions that require a path, if I use paths that assume the working directory is directory1, things work fine. What I don't understand though, is why when I query for the pwd from fastlane, either by using the sh action or even straight Ruby Dir.pwd, both give me the value /MacBook-Pro/directory1/fastlane rather than the working directory I set of /MacBook-Pro/directory1. What am I missing about what fastlane is doing regarding directories here?

like image 306
stonedauwg Avatar asked Feb 23 '17 21:02

stonedauwg


1 Answers

Fastlane has some funky directory behaviour when it comes to running shell commands with sh(). The workaround is to change directory, or prepend your paths with .. when you are running shell commands like pwd.

As per the 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.

like image 167
shocking Avatar answered Sep 22 '22 06:09

shocking