Skip to content

CI: remove (future) deprecated --preserve-env flag#625

Merged
aramprice merged 1 commit into
ubuntu-jammyfrom
sudo-fix
Jun 10, 2026
Merged

CI: remove (future) deprecated --preserve-env flag#625
aramprice merged 1 commit into
ubuntu-jammyfrom
sudo-fix

Conversation

@aramprice

Copy link
Copy Markdown
Member
  • explicitly pass GEM_HOME

Fixes:

sudo: preserving the entire environment is not supported, '--preserve-env' is ignored
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5$ set -e
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5$
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5$ cd "/tmp/build/44575cf5/bosh-linux-stemcell-builder"
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5/bosh-linux-stemcell-builder$ bundle install
Bundler 4.0.13 is running, but your lockfile was generated with 2.5.23. Installing Bundler 2.5.23 and restarting using that version.
Fetching gem metadata from https://rubygems.org/.
Fetching bundler 2.5.23

Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.3.0/cache/bundler-2.5.23.gem`. It is likely that you need to grant write permissions for that path.

^ https://bosh.ci.cloudfoundry.org/teams/stemcell/pipelines/ubuntu-resolute-builder/jobs/build-os-image/builds/1#L6a052874:4:13

Copilot AI review requested due to automatic review settings June 9, 2026 23:37
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@aramprice, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 49 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d9503b1e-ccbb-4d37-a5b3-8f82b3eee9e9

📥 Commits

Reviewing files that changed from the base of the PR and between 2c64dba and 2f2ebda.

📒 Files selected for processing (2)
  • ci/tasks/build.sh
  • ci/tasks/os-images/build.sh

Walkthrough

The PR updates CI build scripts to remove sudo's --preserve-env and instead pass needed environment variables explicitly into the spawned login shells. ci/tasks/build.sh now injects GEM_HOME plus UBUNTU_ADVANTAGE_TOKEN and UBUNTU_FIPS_USE_IAAS_KERNEL into the sudo-launched bash. ci/tasks/os-images/build.sh now uses sudo --set-home --user ubuntu -- with a here-doc and uses bracketed ${VAR} expansions for the rake task arguments.

Suggested reviewers

  • mkocher
  • rkoster
  • lnguyen
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description includes the fix summary and a CI log demonstrating the problem, but does not follow the repository's 'Merge Forward' strategy template which requires branch merge information. Add information about which branch this PR targets and clarify the merge forward strategy steps (e.g., is this PR into ubuntu-jammy with subsequent merge-to-* branches planned).
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: removing the deprecated --preserve-env flag from sudo invocations and replacing it with explicit environment variable passing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sudo-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

julian-hj
julian-hj previously approved these changes Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Concourse stemcell build task to avoid using sudo --preserve-env (which now emits warnings / is ignored) by explicitly ensuring the RubyGems install location (GEM_HOME) is available when running bundle install as the ubuntu user.

Changes:

  • Replaces sudo --preserve-env ... with an invocation intended to pass GEM_HOME into the ubuntu login shell during the build task.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ci/tasks/build.sh Outdated
Comment thread ci/tasks/build.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ci/tasks/build.sh (1)

80-87: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

LGTM!

The sudo invocation change correctly addresses the deprecated --preserve-env issue by explicitly passing GEM_HOME. The syntax is valid: VAR=value before the command passes environment variables through sudo, --set-home sets HOME to ubuntu's home directory, and the -- separator is good practice.

🛡️ Optional: Add defensive validation

Consider adding a validation check before the sudo invocation to fail fast if GEM_HOME is not set in the parent environment:

if [[ -z "${GEM_HOME:-}" ]]; then
  echo "ERROR: GEM_HOME environment variable must be set" >&2
  exit 1
fi

sudo --set-home --user ubuntu GEM_HOME="${GEM_HOME}" -- /bin/bash --login -i <<SUDO

This would provide a clearer error message if the Docker environment is misconfigured, rather than letting bundle install fail with permission errors.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/tasks/build.sh` around lines 80 - 87, Add a defensive check that GEM_HOME
is set before running the sudo block: verify the GEM_HOME environment variable
is non-empty and if it is empty print a clear error to stderr and exit non-zero,
then proceed to the existing sudo invocation (the sudo --set-home --user ubuntu
GEM_HOME="${GEM_HOME}" -- /bin/bash --login -i <<SUDO block) so bundle install
and the subsequent bundle exec rake stemcell:build[...] don't run with a missing
GEM_HOME.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@ci/tasks/build.sh`:
- Around line 80-87: Add a defensive check that GEM_HOME is set before running
the sudo block: verify the GEM_HOME environment variable is non-empty and if it
is empty print a clear error to stderr and exit non-zero, then proceed to the
existing sudo invocation (the sudo --set-home --user ubuntu
GEM_HOME="${GEM_HOME}" -- /bin/bash --login -i <<SUDO block) so bundle install
and the subsequent bundle exec rake stemcell:build[...] don't run with a missing
GEM_HOME.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7cf582ef-afda-4853-8f61-a820b6524813

📥 Commits

Reviewing files that changed from the base of the PR and between b042519 and 02b88bc.

📒 Files selected for processing (1)
  • ci/tasks/build.sh

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 9, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 9, 2026
julian-hj
julian-hj previously approved these changes Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread ci/tasks/os-images/build.sh
Comment thread ci/tasks/build.sh
@aramprice aramprice dismissed stale reviews from julian-hj and coderabbitai[bot] via 2c64dba June 9, 2026 23:56
@aramprice aramprice force-pushed the sudo-fix branch 2 times, most recently from 2c64dba to c0c031c Compare June 9, 2026 23:59
@aramprice aramprice requested a review from Copilot June 10, 2026 00:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/tasks/build.sh`:
- Line 82: Change the variable expansion for UBUNTU_ADVANTAGE_TOKEN in the env
assignment to use the non-assigning default operator ":-" instead of ":=" so the
current shell variable is not modified; locate the env line that sets
UBUNTU_ADVANTAGE_TOKEN (the one using
UBUNTU_ADVANTAGE_TOKEN="${UBUNTU_ADVANTAGE_TOKEN:=}") and replace the operator
so it reads as a default-only expansion
UBUNTU_ADVANTAGE_TOKEN="${UBUNTU_ADVANTAGE_TOKEN:-}" to match the other lines
and maintain consistency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a7e48558-e183-403d-908a-f0a8d2e92da6

📥 Commits

Reviewing files that changed from the base of the PR and between 02b88bc and 2c64dba.

📒 Files selected for processing (2)
  • ci/tasks/build.sh
  • ci/tasks/os-images/build.sh

Comment thread ci/tasks/build.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread ci/tasks/build.sh
Comment thread ci/tasks/os-images/build.sh
Comment thread ci/tasks/os-images/build.sh Outdated
Explicitly pass:
- GEM_HOME
- BUILD_TIME
- UBUNTU_ADVANTAGE_TOKEN
- UBUNTU_FIPS_USE_IAAS_KERNEL

Fixes:
```
sudo: preserving the entire environment is not supported, '--preserve-env' is ignored
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5$ set -e
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5$
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5$ cd "/tmp/build/44575cf5/bosh-linux-stemcell-builder"
ubuntu@21f652d6-b208-4386-b0c0-097e26578228:/tmp/build/44575cf5/bosh-linux-stemcell-builder$ bundle install
Bundler 4.0.13 is running, but your lockfile was generated with 2.5.23. Installing Bundler 2.5.23 and restarting using that version.
Fetching gem metadata from https://rubygems.org/.
Fetching bundler 2.5.23

Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.3.0/cache/bundler-2.5.23.gem`. It is likely that you need to grant write permissions for that path.
```
^ https://bosh.ci.cloudfoundry.org/teams/stemcell/pipelines/ubuntu-resolute-builder/jobs/build-os-image/builds/1#L6a052874:4:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread ci/tasks/os-images/build.sh
Comment thread ci/tasks/build.sh
@aramprice aramprice merged commit dc3c1ee into ubuntu-jammy Jun 10, 2026
13 checks passed
@aramprice aramprice deleted the sudo-fix branch June 10, 2026 00:18
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.

3 participants