Commit 11d5b835 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix CI_PROJECT_DIR handling

parent cdca637e
Pipeline #51235810 passed with stages
in 51 minutes and 53 seconds
......@@ -153,6 +153,11 @@ func (b *Build) StartBuild(rootDir, cacheDir string, sharedDir bool) {
b.RootDir = rootDir
b.BuildDir = path.Join(rootDir, b.ProjectUniqueDir(sharedDir))
b.CacheDir = path.Join(cacheDir, b.ProjectUniqueDir(false))
// invalidate variables cache:
// as some variables are based on dynamic
// state after build starts
b.allVariables = nil
}
func (b *Build) executeStage(ctx context.Context, buildStage BuildStage, executor Executor) error {
......
......@@ -76,6 +76,59 @@ func TestBuildRun(t *testing.T) {
assert.NoError(t, err)
}
func TestBuildPredefinedVariables(t *testing.T) {
e := MockExecutor{}
defer e.AssertExpectations(t)
p := MockExecutorProvider{}
defer p.AssertExpectations(t)
// Create executor only once
p.On("CanCreate").Return(true).Once()
p.On("GetDefaultShell").Return("bash").Once()
p.On("GetFeatures", mock.Anything).Return(nil).Twice()
p.On("Create").Return(&e).Once()
// We run everything once
e.On("Prepare", mock.Anything).
Return(func(options ExecutorPrepareOptions) error {
options.Build.StartBuild("/root/dir", "/cache/dir", false)
return nil
}).Once()
e.On("Finish", nil).Return().Once()
e.On("Cleanup").Return().Once()
// Run script successfully
e.On("Shell").Return(&ShellScriptInfo{Shell: "script-shell"})
e.On("Run", matchBuildStage(BuildStagePrepare)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageGetSources)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageRestoreCache)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageDownloadArtifacts)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageUserScript)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageAfterScript)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageArchiveCache)).Return(nil).Once()
e.On("Run", matchBuildStage(BuildStageUploadOnSuccessArtifacts)).Return(nil).Once()
RegisterExecutor(t.Name(), &p)
successfulBuild, err := GetSuccessfulBuild()
assert.NoError(t, err)
build := &Build{
JobResponse: successfulBuild,
Runner: &RunnerConfig{
RunnerSettings: RunnerSettings{
Executor: t.Name(),
},
},
}
err = build.Run(&Config{}, &Trace{Writer: os.Stdout})
assert.NoError(t, err)
projectDir := build.GetAllVariables().Get("CI_PROJECT_DIR")
assert.NotEmpty(t, projectDir, "should have CI_PROJECT_DIR")
}
func TestBuildRunNoModifyConfig(t *testing.T) {
e := MockExecutor{}
defer e.AssertExpectations(t)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment