Skip to content

Exe download priority, after migration users validation, before logoff#270

Merged
jworkmanjc merged 1 commit into
masterfrom
CUT-5161_updateExeDownloadOrder
Jul 1, 2026
Merged

Exe download priority, after migration users validation, before logoff#270
jworkmanjc merged 1 commit into
masterfrom
CUT-5161_updateExeDownloadOrder

Conversation

@jworkmanjc

@jworkmanjc jworkmanjc commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Update Invoke Script EXE download priority order.

Issues

  • CUT-5161 - Update Invoke EXE Download Order

What does this solve?

This minimal change re-structures the order in which the EXE is downloaded. The goal here is to cache all required assets before migration is invoked and before the logoff task occurs. The ADMU, if prompted to via parameter, will block accounts form logging in during migration. This action should occur as soon as possible after logoff.

Previously the migration user was logged off, then the production exe downloaded to the device. This change downloads the EXE before logoff to ensure account login blocking is triggered as soon as possible.

Is there anything particularly tricky?

NO

How should this be tested?

Run the new invoke script. There should be not new behavior here, just order of operations has changed.

Screenshots


Note

Low Risk
Same operations in a different order with no new migration parameters or logic; failure modes are unchanged aside from failing before logoff if EXE download fails.

Overview
Reorders the ADMU invoke script so gui_jcadmu.exe is validated and obtained (local check + Get-LatestADMUGUIExe) after migration users are loaded and before quser/logoff and the migration batch.

Local EXE pre-check moves out of the parameter validation block into a dedicated #region exeValidation; Get-LatestADMUGUIExe is no longer called at the start of #region migration (path is still passed via guiJcadmuPath). Region comments for dataImport and logoffUsers are cleaned up.

Intent: when BlockAccountLogin is enabled, the production binary is already on disk right after logoff instead of downloading while users are being logged off.

Reviewed by Cursor Bugbot for commit 6f522eb. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the migration flow so it stops early when no eligible users are found.
    • Deferred executable validation and retrieval until after user import, reducing unnecessary checks and downloads.
    • Updated the execution order to better align setup steps before migration begins.

@jworkmanjc
jworkmanjc requested a review from a team as a code owner July 1, 2026 16:58
@jworkmanjc
jworkmanjc requested a review from shashisinghjc July 1, 2026 16:58
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The script reorders local executable validation to occur after determining migration users, adding an early exit when no eligible users exist. Executable pre-check and GUI path retrieval move into a new exeValidation section, the logoffUsers region marker is relocated, and the migration section reuses the previously computed path instead of re-fetching it.

Changes

Execution Order Rework in ADMU Invoke Script

Layer / File(s) Summary
Remove early executable pre-check
jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1
The parameter validation section no longer runs the local executable validation try/catch block at that point.
Deferred exeValidation with early exit
jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1
After Get-MigrationUser, the script exits early if no users are found, then runs a new exeValidation section that pre-checks the local executable and sets $guiJcadmuPath via Get-LatestADMUGUIExe.
Region marker move and reuse of guiJcadmuPath
jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1
The #endregion logoffUsers marker moves after the LeaveDomain/ForceReboot logic, and the migration section reuses the earlier computed $guiJcadmuPath instead of calling Get-LatestADMUGUIExe again.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Script as 3_ADMU_Invoke.ps1
  participant MigrationLookup as Get-MigrationUser
  participant ExeValidation as exeValidation
  participant GuiExe as Get-LatestADMUGUIExe
  participant Migration as Invoke-UserMigrationBatch

  Script->>MigrationLookup: request UsersToMigrate
  MigrationLookup-->>Script: return UsersToMigrate
  alt UsersToMigrate not present
    Script->>Script: exit
  else UsersToMigrate present
    Script->>ExeValidation: run local executable pre-check
    ExeValidation->>GuiExe: retrieve latest gui_jcadmu.exe
    GuiExe-->>ExeValidation: guiJcadmuPath
    Script->>Migration: invoke migration using guiJcadmuPath
  end
Loading

Related issues: None referenced in the provided context.

Related PRs: None referenced in the provided context.

Suggested labels: None

Suggested reviewers: None

🐰 A rabbit hopped the script's course,
Checked users first, then checked the source,
The exe now waits till names are found,
Region markers shuffled around,
One less fetch, the path stays sound.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: moving EXE download earlier after user validation and before logoff.
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.
Description check ✅ Passed The PR description follows the required template and includes the issue, problem, test plan, and notes, with only an empty screenshots section.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CUT-5161_updateExeDownloadOrder

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1`:
- Around line 706-719: The early-exit in the $UsersToMigrate check currently
treats a benign “no users to migrate” state as a failure. Update the exit path
near the initial data import logic so the no-op case returns a success code
instead of failing the JumpCloud run, and keep exit 1 only for real errors in
the surrounding migration flow. Use the $UsersToMigrate check and the existing
exeValidation block as anchors when making the change.
🪄 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: CHILL

Plan: Enterprise

Run ID: 9c5035e4-54f2-4763-89d5-5f023706feb1

📥 Commits

Reviewing files that changed from the base of the PR and between c1fb36a and 6f522eb.

📒 Files selected for processing (1)
  • jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1

Comment on lines 706 to +719
if (-not $UsersToMigrate) { Write-Host "[status] No users to migrate, exiting..."; exit 1 }
#endregion dataImport

#region exeValidation
try {
$localExeValidation = Test-RequiredLocalExeFiles -localEXEs $localEXEs
if ($localExeValidation) { Write-Host "[STATUS] Local executable pre-check completed successfully." }
} catch {
Write-Host "[ERROR] Local executable validation failed: $_"
exit 1
}
$guiJcadmuPath = Get-LatestADMUGUIExe -useLocalEXEs $localEXEs -BypassValidation $bypassExeValidation
#endregion exeValidation

@coderabbitai coderabbitai Bot Jul 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Early-exit uses failure exit code for a benign "no users" state.

The new early exit at Line 706 calls exit 1 when $UsersToMigrate is empty. For the Description data source, Get-MgUserFromDesc returns $null simply when there are no pending users to migrate (e.g., all users already migrated, or a routine check-in) — this is not necessarily an error condition. Exiting with code 1 will likely be recorded as a failed JumpCloud command run, which can generate false-positive failure alerts for otherwise-healthy systems.

This also appears to be genuinely new behavior (per the AI summary), which conflicts with the PR description's statement that no new behavior beyond reordering is expected.

Consider using exit 0 for this no-op case, or reserve exit 1 for genuine failures.

💡 Proposed fix
-if (-not $UsersToMigrate) { Write-Host "[status] No users to migrate, exiting..."; exit 1 }
+if (-not $UsersToMigrate) { Write-Host "[status] No users to migrate, exiting..."; exit 0 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (-not $UsersToMigrate) { Write-Host "[status] No users to migrate, exiting..."; exit 1 }
#endregion dataImport
#region exeValidation
try {
$localExeValidation = Test-RequiredLocalExeFiles -localEXEs $localEXEs
if ($localExeValidation) { Write-Host "[STATUS] Local executable pre-check completed successfully." }
} catch {
Write-Host "[ERROR] Local executable validation failed: $_"
exit 1
}
$guiJcadmuPath = Get-LatestADMUGUIExe -useLocalEXEs $localEXEs -BypassValidation $bypassExeValidation
#endregion exeValidation
if (-not $UsersToMigrate) { Write-Host "[status] No users to migrate, exiting..."; exit 0 }
`#endregion` dataImport
`#region` exeValidation
try {
$localExeValidation = Test-RequiredLocalExeFiles -localEXEs $localEXEs
if ($localExeValidation) { Write-Host "[STATUS] Local executable pre-check completed successfully." }
} catch {
Write-Host "[ERROR] Local executable validation failed: $_"
exit 1
}
$guiJcadmuPath = Get-LatestADMUGUIExe -useLocalEXEs $localEXEs -BypassValidation $bypassExeValidation
`#endregion` exeValidation
🤖 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 `@jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1`
around lines 706 - 719, The early-exit in the $UsersToMigrate check currently
treats a benign “no users to migrate” state as a failure. Update the exit path
near the initial data import logic so the no-op case returns a success code
instead of failing the JumpCloud run, and keep exit 1 only for real errors in
the surrounding migration flow. Use the $UsersToMigrate check and the existing
exeValidation block as anchors when making the change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is correct, if there are no users to migrate, we do want to throw an exit 1 to indicate something happened that we didn't expect. In this context an exit code 1 is good enough to denote there was an error with data prep. If no users are able to migrated I want an exit code 1.

An alternative would be to define a table of new exit codes:
1 error
2 no users to migrate
3 data validation error etc

The team can take this back and work as a separate card but for this change it's fine to keep it as is.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@jworkmanjc, understood — thanks for the clarification. Keeping exit 1 for the "no users to migrate" case makes sense given the current convention of using exit 1 to denote any unexpected/error condition in this script. The idea of a structured exit code table (e.g., 1=error, 2=no users, 3=data validation) is a nice enhancement for more granular alerting/triage, but agreed that's reasonable to defer as a separate follow-up card rather than bundling it into this reorder-focused PR.

Let me know if you'd like me to open a follow-up issue to track the structured exit code idea.


✏️ Learnings added
Learnt from: jworkmanjc
Repo: TheJumpCloud/jumpcloud-ADMU PR: 270
File: jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1:706-719
Timestamp: 2026-07-01T17:19:18.338Z
Learning: In `jumpcloud-ADMU-Advanced-Deployment/InvokeFromJCAgent/3_ADMU_Invoke.ps1` (JumpCloud ADMU Invoke Script), when `$UsersToMigrate` is empty/null after the data import step, the script intentionally exits with `exit 1` (not `exit 0`), even though this can represent a benign "no pending users" state (e.g., via `Get-MgUserFromDesc`). This is a deliberate design choice by the team (per maintainer jworkmanjc): exit code 1 is used broadly to denote "something happened that we didn't expect" including data prep issues, not just hard failures. A future enhancement being considered (not yet planned) is a structured exit code table (e.g., 1=general error, 2=no users to migrate, 3=data validation error) to allow finer-grained alerting, but this exit-code granularity work is out of scope for reorder-focused PRs and would be tracked as a separate card.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@gweinjc
gweinjc self-requested a review July 1, 2026 17:25
@jworkmanjc
jworkmanjc merged commit a9509c0 into master Jul 1, 2026
12 checks passed
@jworkmanjc
jworkmanjc deleted the CUT-5161_updateExeDownloadOrder branch July 1, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants