1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/cnbutils/project/resolve_path.go
Ralf Pannemans 4b2f61589d
feat(cnbbuild) enable multi image build (#3521)
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Pavel Busko <pavel.busko@sap.com>
Co-authored-by: Sumit Kulhadia <sumit.kulhadia@sap.com>
2022-02-15 14:39:14 +01:00

43 lines
952 B
Go

package project
import (
"path/filepath"
"github.com/SAP/jenkins-library/pkg/cnbutils"
"github.com/SAP/jenkins-library/pkg/log"
)
// 1. If "path" is a directory, check for "${path}/${descriptor}"
// 2. If "path" is a file, check for "${PWD}/${descriptor}"
func ResolvePath(descriptor, path string, utils cnbutils.BuildUtils) (string, error) {
isDir, err := utils.DirExists(path)
if err != nil {
return "", err
}
if isDir {
return getFilename(path, descriptor, utils)
}
pwd, err := utils.Getwd()
if err != nil {
return "", err
}
return getFilename(pwd, descriptor, utils)
}
func getFilename(folder, filename string, utils cnbutils.BuildUtils) (string, error) {
descPath := filepath.Join(folder, filename)
exists, err := utils.FileExists(descPath)
if err != nil {
return "", err
}
if exists {
return descPath, nil
}
log.Entry().Infof("Project descriptor with the path '%s' was not found", descPath)
return "", nil
}