Skip to content

Commit

Permalink
add the ability to choose the working dir from different ref for the …
Browse files Browse the repository at this point in the history
…decorated container
  • Loading branch information
droslean committed Jul 16, 2019
1 parent c68670e commit 94900cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions prow/apis/prowjobs/v1/types.go
Expand Up @@ -546,6 +546,12 @@ type Refs struct {
// set, <root-dir>/src/github.com/org/repo will be
// used as the default.
PathAlias string `json:"path_alias,omitempty"`

// WorkDir defines if the location of the cloned
// repository will be used as the default working
// directory.
WorkDir bool `json:"workdir,omitempty"`

// CloneURI is the URI that is used to clone the
// repository. If unset, will default to
// `https://github.com/org/repo.git`.
Expand Down
11 changes: 10 additions & 1 deletion prow/pod-utils/decorate/podspec.go
Expand Up @@ -553,14 +553,23 @@ func decorate(spec *coreapi.PodSpec, pj *prowapi.ProwJob, rawEnv map[string]stri
spec.Volumes = append(spec.Volumes, logVolume, toolsVolume, gcsVol)

if len(refs) > 0 {
spec.Containers[0].WorkingDir = clone.PathForRefs(codeMount.MountPath, refs[0])
spec.Containers[0].WorkingDir = determineWorkDir(codeMount.MountPath, refs)
spec.Containers[0].VolumeMounts = append(spec.Containers[0].VolumeMounts, codeMount)
spec.Volumes = append(spec.Volumes, append(cloneVolumes, codeVolume)...)
}

return nil
}

func determineWorkDir(baseDir string, refs []prowapi.Refs) string {
for _, ref := range refs {
if ref.WorkDir {
return clone.PathForRefs(baseDir, ref)
}
}
return clone.PathForRefs(baseDir, refs[0])
}

const (
// RequirePassingEntries causes sidecar to return an error if any entry fails. Otherwise it exits cleanly so long as it can complete.
RequirePassingEntries = true
Expand Down

0 comments on commit 94900cf

Please sign in to comment.