What is the difference between `before_script`, `script` and `after_script`?
BeginnerConceptGitLab CI
Answer
before_script and script are concatenated and run in the same shell, so a failure in either fails the job and variables persist between them. after_script runs in a separate shell, after the job even on failure (but not if the job is cancelled or times out hard), so it does not see variables or changes from script, though it sees the working directory files. Use it for cleanup and uploading diagnostics.
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate