Boolean input not passed correctly to reusable workflow - github

I have an invoking and a called (reusable) workflow.
Here is the input of the reusable one:
stg_image_build:
description: whether to build the staging image
required: true
type: boolean
default: false
Here is the relevant part of the calling workflow
push_to_stg:
description: "Build and push image to staging registry"
type: boolean
default: false
required: true
...
build-and-push-image:
uses: path/to/reusable/workflow.yaml#master
with:
stg_image_build: ${{ inputs.push_to_stg }}
This fails as follows:
The template is not valid. .github/workflows/calling.yaml (Line: 72, Col: 24): Unexpected type of value '', expected type: Boolean.
The error refers to this line:
stg_image_build: ${{ inputs.push_to_stg }}
Why?

Related

GitHub actions: if conditionals in execution of step fails

I want to run a GitHub actions step if an env var matches a value
- name: send slack failure
uses: rtCamp/action-slack-notify#v2
if: env.STATUS_MESSAGE != "Success"
However the above syntax is marked as error:
The workflow is not valid. .github/workflows/file.yaml (Line: 107, Col: 13): Unexpected symbol: '"Success"'. Located at position 23 within
How can I compare the value of the env var to a given value?
The correct syntax is:
if: ${{ env.STATUS_MESSAGE != 'Success' }}
${{ and }} are optional

Referencing json list value created in Rundeck Data Workflow step

Rundeck job: When I create data in data workflow step as json list
{
"repo": ["repo1","repo2","repo3"],
"myrepo": "repo4"
}
how can I access the elements in the list from inline script in next step?
#stub.repo[1]#
doesn't work
#stub.myrepo#
works fine
Data Workflow step executed
Script:
echo "value: #stub.repo[1]]#"
echo "value2: #stub.myrepo#"
Result:
value:
value2: repo4
The easiest way to catch that array is to use the jq-JSON mapper log filter plugin in any step like the command step or script step (here are the releases, here is how to install the plugin, and here how Log filters works).
Using this plugin you can use the array positions directly, e.g: ${data.data.0}, ${data.data.1}, etc.
Job definition example with your JSON output for testing.
- defaultTab: summary
description: ''
executionEnabled: true
group: JSON
id: f0d2843f-8de3-4984-a9ae-2fd7ab3963ae
loglevel: INFO
name: test-json-array
nodeFilterEditable: false
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- plugins:
LogFilter:
- config:
filter: .[]
logData: 'true'
prefix: data
type: json-mapper
script: |-
cat <<-END
{
"repo": ["repo1","repo2","repo3"],
"myrepo": "repo4"
}
END
- exec: echo ${data.data.0}
keepgoing: false
strategy: node-first
uuid: f0d2843f-8de3-4984-a9ae-2fd7ab3963ae
Result.
More info about the plugin here.

How to properly use expression results as booleans on Azure Devops pipelines?

I'm trying to use an or expression to define a boolean on a template as follows:
parameters:
- name: A
default: true
- name: B
default: false
stages:
- template: bacon.yml#template
parameters:
booleanParameter: or(eq(${{ parameters.A }}, true), eq(${{ parameters.B}}, true))
In my head, it should work just fine, yet I keep getting this same error:
The 'booleanParameter' parameter value 'or(eq(True, true), eq(False, true))' is not a valid Boolean.
I've tried some small variations of syntax, all of them resulting in the same error.
What am I missing here?
You should use template expression to wrap whole expression:
booleanParameter: ${{ or(eq(parameters.A, true), eq(parameters.B, true)) }}

Setting with for local action script

Is it possible to set with parameters not process.env.message for local scripts?
Getting error:
The workflow is not valid. .github/workflows/message.yml (Line: n, Col: n): Unexpected value 'run' .github/workflows/message.yml (Line: n, Col: n): Required property is missing: uses
e.g.
.github/scripts/action.js
#!/usr/bin/env node
import * as core from '#actions/core'
async function run() {
if (core.getInput('message') !== 'must-message') {
core.setFailed('message is invalid')
}
}
run()
./github/workflows/message.yml
name: "message"
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: check message
run: .github/scripts/action.js
with:
message: 'must-message'

AZP: Is there a best practice to be able to "namespace" script tasks in yaml templates for usage of variables?

In Azure Pipelines: my main problem is, if I create a yml template and have some logic inside that template in a script task where I want to set a variable, i need the
name: "pseudonamespace" to reference that variable further down in that template via
$(pseudonamespace.variablename)
An example, where the script part does nothing overtly useful, but should demonstrate my problem:
mytemplate.yml:
parameters:
- name: isWindowsOnTarget
type: boolean
default: true
steps:
- script: |
if [ "${{lower(parameters.isWindowsOnTarget)}}" == "true" ]; then
delimiter="\\"
else
delimiter="/"
fi
echo "##vso[task.setvariable variable=myCoolVariable;isOutput=true]$delimiter"
name: MyFakeNameSpace
...
- task: SomeTask#0
inputs:
myInput: $(MyFakeNameSpace.myCoolVariable)
This codeblock works; but only, if, in a job, I only instanciate it once:
- template: mytemplate.yml#templates
parameters:
isWindowsOnTarget: true
If I would need that template twice, differently parameterized, I get the error that the name of the script block needs to be unique.
Is there any useful possibility I'm not currently thinking about other than to have an extra parameter for the template that I could basically just call "UniqueNamespace"?
There is no much space to move. Your task needs a unique name as later as you mention for output parameters it works like a namespace. So the best and the only way you have is to provide another parameter which would be task name.
parameters:
- name: isWindowsOnTarget
type: boolean
default: true
- name: taskName
type: string
steps:
- script: |
if [ "${{lower(parameters.isWindowsOnTarget)}}" == "true" ]; then
delimiter="\\"
else
delimiter="/"
fi
echo "##vso[task.setvariable variable=myCoolVariable;isOutput=true]$delimiter"
name: ${{ parameters.taskName }}
...
- task: SomeTask#0
inputs:
myInput: $(MyFakeNameSpace.myCoolVariable)
and then:
- template: mytemplate.yml#templates
parameters:
isWindowsOnTarget: true
taskName: MyFakeNameSpace
- template: mytemplate.yml#templates
parameters:
isWindowsOnTarget: true
taskName: MyFakeNameSpace2
In fact when you do not provide a name Azure DevOps assign a unique name. However, in this way you don't know the name till runtime.