diff --git a/engine/api/workflow/dao_run.go b/engine/api/workflow/dao_run.go index 36f4ea40b9..9a9187039a 100644 --- a/engine/api/workflow/dao_run.go +++ b/engine/api/workflow/dao_run.go @@ -430,7 +430,7 @@ func loadRun(db gorp.SqlExecutor, loadOpts LoadRunOptions, query string, args .. return &wr, nil } -// CanBeRun return boolean to know if a wokrflow node run can be run or not +// CanBeRun return boolean to know if a workflow node run can be run or not //TODO: if no bugs are found, it could be used to refactor process.go func CanBeRun(workflowRun *sdk.WorkflowRun, workflowNodeRun *sdk.WorkflowNodeRun) bool { if !sdk.StatusIsTerminated(workflowNodeRun.Status) { diff --git a/engine/worker/cmd_tmpl.go b/engine/worker/cmd_tmpl.go index 44ebdf1d89..3a170bbf1c 100644 --- a/engine/worker/cmd_tmpl.go +++ b/engine/worker/cmd_tmpl.go @@ -121,9 +121,15 @@ func (wk *currentWorker) tmplHandler(w http.ResponseWriter, r *http.Request) { return } - vars := sdk.ParametersToMap(wk.currentJob.params) + tmpvars := map[string]string{} + for _, v := range wk.currentJob.buildVariables { + tmpvars[v.Name] = v.Value + } + for _, v := range wk.currentJob.params { + tmpvars[v.Name] = v.Value + } - res, err := interpolate.Do(string(btes), vars) + res, err := interpolate.Do(string(btes), tmpvars) if err != nil { log.Error("Unable to interpolate: %v", err) newError := sdk.NewError(sdk.ErrWrongRequest, err) diff --git a/tests/fixtures/ITSCWRKFLW9/ITSCWRKFLW9.yml b/tests/fixtures/ITSCWRKFLW9/ITSCWRKFLW9.yml new file mode 100644 index 0000000000..e5d8e3dcae --- /dev/null +++ b/tests/fixtures/ITSCWRKFLW9/ITSCWRKFLW9.yml @@ -0,0 +1,3 @@ +name: ITSCWRKFLW9-WORKFLOW +version: v1.0 +pipeline: worker-tmpl \ No newline at end of file diff --git a/tests/fixtures/ITSCWRKFLW9/worker-tmpl.pip.yml b/tests/fixtures/ITSCWRKFLW9/worker-tmpl.pip.yml new file mode 100644 index 0000000000..c481046a26 --- /dev/null +++ b/tests/fixtures/ITSCWRKFLW9/worker-tmpl.pip.yml @@ -0,0 +1,22 @@ +version: v1.0 +name: worker-tmpl +jobs: +- job: New Job + steps: + - script: + - worker export foo "bar" + - script: + - '#!/bin/bash' + - echo "cds.build.foo = {{.cds.build.foo}}" + - echo -n "{" > inputfile + - echo -n "{.cds.build" >> inputfile + - echo -n ".foo}}" >> inputfile + - echo "" >> inputfile + - echo "input file is:" + - cat inputfile + - echo "running worker tmpl..." + - worker tmpl inputfile outputfile + - echo "output file is:" + - cat outputfile + - echo "grep bar in outputfile :" + - cat outputfile | grep bar diff --git a/tests/sc_workflow_run_cmd_tmpl.yml b/tests/sc_workflow_run_cmd_tmpl.yml new file mode 100644 index 0000000000..a1cfc040b4 --- /dev/null +++ b/tests/sc_workflow_run_cmd_tmpl.yml @@ -0,0 +1,34 @@ +name: Create a simple workflow (ITSCWRKFLW9) +testcases: +- name: assert filepath, your current directory must be at the root of this project + steps: + - script: '[ -f ./tests/fixtures/ITSCWRKFLW9/worker-tmpl.pip.yml ]' + - script: '[ -f ./tests/fixtures/ITSCWRKFLW9/ITSCWRKFLW9.yml ]' + +- name: prepare test + steps: + - script: "{{.cds.build.cdsctl}} project remove --force ITSCWRKFLW9" + - script: "{{.cds.build.cdsctl}} group remove --force ITSCWRKFLW9 " + - script: "{{.cds.build.cdsctl}} project add ITSCWRKFLW9 ITSCWRKFLW9" + +- name: push workflow + steps: + - script: {{.cds.build.cdsctl}} workflow push ITSCWRKFLW9 ./tests/fixtures/ITSCWRKFLW9/*.yml --skip-update-files + assertions: + - result.code ShouldEqual 0 + +- name: run workflow + steps: + - script: {{.cds.build.cdsctl}} workflow run ITSCWRKFLW9 ITSCWRKFLW9-WORKFLOW + assertions: + - result.code ShouldEqual 0 + - "result.systemout ShouldContainSubstring Workflow ITSCWRKFLW9-WORKFLOW #1 has been launched" + +- name: the workflow should be successful + steps: + - script: {{.cds.build.cdsctl}} workflow status ITSCWRKFLW9 ITSCWRKFLW9-WORKFLOW 1 --format json + assertions: + - result.code ShouldEqual 0 + - result.systemoutjson.status ShouldEqual Success + retry: 30 + delay: 10