Skip to content

Commit

Permalink
fix(worker): worker tmpl with exported var (#3834)
Browse files Browse the repository at this point in the history
* fix(worker): worker tmpl with exported var

Signed-off-by: Yvonnick Esnault <[email protected]>

* it test

Signed-off-by: Yvonnick Esnault <[email protected]>

* it

Signed-off-by: Yvonnick Esnault <[email protected]>

* cr

Signed-off-by: Yvonnick Esnault <[email protected]>

* fix it

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored and richardlt committed Jan 9, 2019
1 parent 1ccb27b commit df3a930
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion engine/api/workflow/dao_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions engine/worker/cmd_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/ITSCWRKFLW9/ITSCWRKFLW9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: ITSCWRKFLW9-WORKFLOW
version: v1.0
pipeline: worker-tmpl
22 changes: 22 additions & 0 deletions tests/fixtures/ITSCWRKFLW9/worker-tmpl.pip.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions tests/sc_workflow_run_cmd_tmpl.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit df3a930

Please sign in to comment.