Skip to content

Commit 629b7e1

Browse files
committed
Propagate P4CLIENT and BUILD_REF to agent subprocess environment
- Add P4Client field to CheckoutResult so the worker can pass the workspace name to graph execution - Set P4CLIENT and BUILD_REF in the subprocess env - Add CredentialTypeP4 to core credential types
1 parent 5e94f52 commit 629b7e1

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

agent/vcs/p4.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (p *P4Provider) Checkout(ctx context.Context, url, ref, pipeline, destDir s
9393
return CheckoutResult{}, fmt.Errorf("p4 sync pipeline file failed: %w", err)
9494
}
9595

96-
return CheckoutResult{Dir: root, Persistent: true}, nil
96+
return CheckoutResult{Dir: root, Persistent: true, P4Client: p.clientName}, nil
9797
}
9898

9999
// Create temporary workspace
@@ -132,7 +132,7 @@ func (p *P4Provider) Checkout(ctx context.Context, url, ref, pipeline, destDir s
132132
return CheckoutResult{}, fmt.Errorf("p4 sync pipeline file failed: %w", err)
133133
}
134134

135-
return CheckoutResult{Dir: absDir}, nil
135+
return CheckoutResult{Dir: absDir, P4Client: p.clientName}, nil
136136
}
137137

138138
func (p *P4Provider) Cleanup(ctx context.Context) error {

agent/vcs/vcs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type CheckoutResult struct {
3333
Persistent bool
3434
// SHA is the resolved commit SHA (or changelist number for P4) after checkout.
3535
SHA string
36+
// P4Client is the Perforce workspace name created or reused during checkout.
37+
// The worker should set P4CLIENT in the subprocess environment so that
38+
// p4 commands within the graph can operate on the same workspace.
39+
P4Client string
3640
}
3741

3842
// Provider handles VCS checkout operations.

agent/worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,16 @@ func (w *Worker) execute(ctx context.Context, job *ClaimResponse) {
358358
env = append(env, "BUILD_TMPDIR="+tmpDir)
359359
env = append(env, "BUILD_VCS_TYPE="+job.VCSType)
360360
env = append(env, "BUILD_VCS_URL="+job.VCSURL)
361+
env = append(env, "BUILD_REF="+ref)
361362
if job.RepoID != "" {
362363
env = append(env, "BUILD_REPO_ID="+job.RepoID)
363364
}
364365
if checkout.SHA != "" {
365366
env = append(env, "BUILD_COMMIT_SHA="+checkout.SHA)
366367
}
368+
if checkout.P4Client != "" {
369+
env = append(env, "P4CLIENT="+checkout.P4Client)
370+
}
367371

368372
// Resolve env mappings from trigger config (if present)
369373
if len(job.EnvMappings) > 0 && job.MatrixValues != nil {

core/base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
CredentialTypeSSH CredentialType = iota
5050
CredentialTypeUsernamePassword
5151
CredentialTypeAccessKey
52+
CredentialTypeP4
5253
)
5354

5455
type Credentials interface {

0 commit comments

Comments
 (0)