Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some env vars updates #175

Merged
merged 18 commits into from
Mar 5, 2018
Merged

Some env vars updates #175

merged 18 commits into from
Mar 5, 2018

Conversation

harrietgrace
Copy link
Contributor

@harrietgrace harrietgrace commented Nov 27, 2017

Alphabetising the env vars, because it kills me every time I look at this page that they're not in order. Also, makes it much easier for people to find what they're looking for 💁🏻

Possibly adding some more things to this page, so leaving this PR as a WIP for the moment.

  • Add tables to the writable variables bit
  • Add how-it-works section
  • Add info on the bootstrap vars
  • Make all the lonely dot points into sentences

Later:

  • Add image to explain precedence
  • Add the writable variables table

@lox
Copy link
Contributor

lox commented Jan 5, 2018

Alphabetising the env vars, because it kills me every time

🙇🏼‍♂️

Let me know when you want feedback!

@harrietgrace
Copy link
Contributor Author

Thanks @lox! Do you think there's anything major missing from the page outline? I added headings for things I think would be handy/the sections that @sj26 mentioned in Basecamp - anything else you think would be useful?

@lox
Copy link
Contributor

lox commented Jan 5, 2018

Looks pretty good to me, another way to cut it would be:

  • Read-only variables
  • Configurable variables
  • Storing secrets (e.g don't use env)
  • Defining your own variables

@lox
Copy link
Contributor

lox commented Jan 5, 2018

What did you have planned for interpolating?

@harrietgrace
Copy link
Contributor Author

Those headings sound great 👌🏻

For interpolating, I meant not interpolating at all 😅 I'm planning for that to actually be a section about how env vars are merged together, explaining how they override each other depending on what level you set them at. I've just added in a big lot of notes on how this works after talking with @sj26. Will clean those up next week ⚡️

Fixed merge conflict in env vars file:
- added the new item to the vars table from the third party pr
- alphabetised the env vars, as per existing pr
- added section on how env vars work, as per existing pr
@harrietgrace
Copy link
Contributor Author

harrietgrace commented Jan 16, 2018

Merged in master and new env var table item from 3rd party pr 🎉

@harrietgrace
Copy link
Contributor Author

@sj26 could you please have a quick read over the 'How environment variables do the thing' section, and let me know if it reflects your ideas about the process? I didn't change a whole lot from our conversation the other day, but it would be good to double check the overall thing 😊

</tr>
<tr>
<th><code>BUILDKITE_BUILD_ID</code></th>
<td>The UUID of the original build this was rebuilt from. <p class="Docs__api-param-eg"><em>Example:</em> <code>"4735ba57-80d0-46e2-8fa0-b28223a86586"</code>, or <code>""</code> if not a rebuild.</p></td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, maybe BUILDKITE_BUILD_ID and BUILDKITE_REBUILT_FROM_BUILD_ID have been mixed up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, some copy pasta most likely. Should it just be 'The UUID of the build'?

</tr>
<tr>
<th><code>BUILDKITE_PULL_REQUEST_REPO</code></th>
<td>The repository URL of the third-party pull request. <p class="Docs__api-param-eg"><em>Example:</em> <code>"git://github.com/acme-inc/my-project.git"</code>, or <code>""</code> if not a pull request.</p></td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repository URL of the third-party pull request

I'm pretty sure this is present for all pull requests, not just third-party ones

</tr>
<tr>
<th><code>BUILDKITE_REBUILT_FROM_BUILD_NUMBER</code></th>
<td>The UUID of the original build this was rebuilt from. <p class="Docs__api-param-eg"><em>Example:</em> <code>"1514"</code>, or <code>""</code> if not a rebuild.</p></td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, UUID => number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure I understand. What's the difference between a build number and a build UUID?

</table>

Bootstrap vars:
BUILDKITE_DISABLE_GIT_SUBMODULES
BUILDKITE_REFSPEC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILDKITE_REFSPEC can be supplied from the api, ui, or wherever triggers the build, or any hook before checkout, to override how a build's source code is fetched in the bootstrap using git fetch origin $BUILDKITE_REFSPEC.

https://github.com/buildkite/agent/blob/master/bootstrap/bootstrap.go#L648-L658

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is this purely for the branch name? Or can you put anything in that var?

Copy link
Member

@sj26 sj26 Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, not really for plain branch names, no — that's a more common scenario and takes a different code path. This variable was added for a specific customer who was using phabricator or something and wanted very specific control over what git fetched code to run builds against, so we let them specify it using this variable. It could be just a branch name (but you'd probably just use BUILDKITE_BRANCH for that) but is more likely for custom refspecs like +refs/weird/123abc:refs/local/weird/456 or something. I'm almost tempted to say this variable shouldn't be documented — it was only for a very specific use case.

</table>

Bootstrap vars:
BUILDKITE_DISABLE_GIT_SUBMODULES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILDKITE_DISABLE_GIT_SUBMODULES can be supplied from the api, ui, or wherever triggers the build, or any hook before checkout to disable fetching any git submodules during checkout.

- more details on setting vars in a pipeline.yml:
- there are two places in a pipeline.yml file that you can set env vars:
- in the `env` attribute of command or trigger steps
- at the top of the yaml file, before you define your pipeline's steps (this will set the defined variable on each of the command steps in the pipeline, and is equivalent to setting the `env` attribute on every step)
Copy link
Member

@sj26 sj26 Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one caveat to this — shared env (at the top level of the pipeline.yml) currently overrides the step level env. So:

env:
- FOO=bar
steps:
- ...
  env:
  - FOO=baz

Intuitively it looks like the job should be run with FOO=baz, but currently it is run with FOO=bar. We're thinking about changing it from this to to what you'd expect so that FOO=baz wins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Right. Is there a vague eta for the decision about that possible change? If it's going to be a while off, I'll publish this telling people about how it overrides now. If it's imminent, I'll hold off until after we've changed it or we decide we don't want to 👌🏻

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @lox would have a better idea?


- these are merged together in the following way:
(maybe put an image or example code here)
bk env (most important, not overridden by the following bits) > build > step > project (least important, can be overridden by everything else)
Copy link
Member

@sj26 sj26 Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth noting here maybe that step = step or pipeline.yml, even if it feels like pipeline uploads should override the build env


- more details on setting vars in a Trigger step:
- env vars set in a trigger step end up as build-level env on the newly created build
- NOTE: the 'all steps env' from the top of a pipeline.yaml isn't applied to trigger steps, the only env that applies to trigger steps is what you choose to set in that trigger step's `env` attribute (which ends up as build env in the new build)
Copy link
Member

@sj26 sj26 Jan 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth adding that you can copy env to the trigger env using env interpolation from agent 3:

env:
- FOO=bar
steps:
- trigger: some-pipeline
  build:
    env:
    - FOO=$FOO # triggered build will have `FOO=bar`

and that trigger env becomes "build env" in the triggered build

- any environment variables that were inherited from how you started the process (i.e. systemd sets some env vars for you)

For a list of variables/flags you can set on your agent, see the [`buildkite-agent start` page](/docs/agent/cli-start).
For a deeper look at what's involved in starting the agent, you can see the the [`buildkite-agent start` code on github](https://github.com/buildkite/agent/blob/master/clicommand/agent_start.go).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth explicitly mentioning that the agent environment influences how the agent runs your job, but does not get directly copied into the job's environment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see it's kinda covered in the next section.

- some vars are created fresh at this point
- describe the agent that the job is running on
- vars to tell the bootstrap and other prebaked commands what to do
- e.g. we don't give the job environment the agent's registration token, we instead create a new access token for this specific job
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is something which often trips folks up

@sj26
Copy link
Member

sj26 commented Jan 19, 2018

Looking good, @harrietgrace!

@harrietgrace harrietgrace changed the title [WIP] Some env vars updates Some env vars updates Feb 21, 2018
@harrietgrace
Copy link
Contributor Author

@keithpitt Could I please get you to have a quick squiz at this? Sam helped me sort out what was going on in each section, I just wanted to get an extra set of eyes on it before I merge it 😊Mostly looking for feedback on formatting, information organisation, and spelling. But content feedback is welcome too!

Screenshots of the new section from dev (I've also alphabetised the vars table at the top, but this is the main bit of the pr):

screen shot 2018-02-21 at 4 32 20 pm

screen shot 2018-02-21 at 4 36 53 pm

@keithpitt
Copy link
Member

@harrietgrace I don't think we use the word project anywhere anymore, should it be pipeline?

@harrietgrace
Copy link
Contributor Author

@keithpitt yep it should totally be pipeline! How did that even sneak in... 😅

@harrietgrace harrietgrace merged commit 690938c into master Mar 5, 2018
@harrietgrace harrietgrace deleted the update-env-vars branch March 5, 2018 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants