Environment Locking
Environment locking prevents concurrent access to shared environments. When a pipeline or developer locks an environment, others must wait until the lock is released, ensuring deployments don't conflict.
Why Lock Environments?
Without locking, multiple operations can interfere with each other:
┌─────────────────────────────────────────────────────────────────┐
│ Without Locking (Problem) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Pipeline A ────────> Deploy v1.0 ─────────┐ │
│ │ │
│ Pipeline B ────────> Deploy v1.1 ────┐ │ │
│ ▼ ▼ │
│ ┌──────────────┐ │
│ │ UAT │ Conflict! │
│ │ (broken) │ │
│ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ With Locking (Solution) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Pipeline A ── Lock ──> Deploy v1.0 ── Unlock ─┐ │
│ │ │
│ Pipeline B ── Wait... ─────────────── Lock ───┼──> Deploy v1.1│
│ ▼ │
│ ┌──────────────┐ │
│ │ UAT │ │
│ │ (working) │ │
│ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘How Locking Works
Lock Request Flow
Request Lock: Pipeline requests a lock, gets a ticket ID
Queue Position: If environment is locked, request is queued
Acquire Lock: When available, pipeline acquires the lock
Perform Operations: Deploy, test, etc.
Release Lock: Unlock when finished
Lock Properties
ticketId
Unique identifier for the lock request
lockedBy
Who holds the lock (user or application)
lockReason
Why the lock was acquired
expiresAt
When the lock expires
leaseDuration
How long the lock is valid
Requesting a Lock
Basic Lock Request
Output:
With Extended Duration
Acquiring the Lock
Once your request reaches the front of the queue:
This command:
Waits for the lock to be available (polls every 30 seconds)
Acquires the lock when available
Retrieves credentials
Authenticates locally
Wait for Lock (Automatic)
The --lock-ticket-id flag automatically waits for lock acquisition:
Releasing a Lock
Manual Release
Automatic Expiration
Locks automatically expire after the lease duration. This prevents orphaned locks from blocking deployments indefinitely.
CI/CD Integration
GitHub Actions with Locking
Handling Lock Timeouts
Lock Queue Management
View Queue Status
Output:
Cancel a Lock Request
Lock Credentials Security
When you acquire a lock, credentials are only revealed at that point:
This ensures credentials are only provided to the lock holder.
Troubleshooting
Lock Not Releasing
Check if the lock holder is still active:
If the lock is orphaned (holder crashed), wait for expiration or contact an admin.
Stuck in Queue
Check queue position
Verify your ticket ID is correct
Check if you have permission to lock
"Lock already held"
You already hold a lock on this environment:
Credentials Not Returned
Ensure you're using --lock-ticket-id when fetching:
Related Topics
Environments - Environment management overview
Server Authentication - Authenticate with sfp-server
Accessing Environments - Practical examples
Last updated