Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 2.1 KB

05.4.1_inputs.md

File metadata and controls

52 lines (39 loc) · 2.1 KB

Inputs {docsify-ignore-all}

This is an optional parameter used to allow workflows to define data the action will use at runtime.

action.yml

inputs:
  myfirstinput:
    description: I should describe the purpose of the input here
    required: false
    default: this string is used when no value is supplied in a workflow

In the example above myfirstinput is the name of the input. We see that it contains a description, whether or not it is required, and what the default value is for the input.

Adding more than one input to an action.yml file is quite easy.

action.yml

inputs:
  myfirstinput:
    description: I should describe the purpose of the input here
    required: false
    default: this string is used when no value is supplied in a workflow
  mysecondinput:
    description: some other description about this input
    required: true

Since mysecondinput is required we don't have to give it a default value. This action will fail to run if the second parameter isn't supplied in the workflow. Speaking of workflows, let's see how to make sure we are supplying input to an action when it expects it.

We will use the action.yml input metadata that we defined above for this example.

workflow.yml

jobs:
  my_first_job:
    name: My Job Name
      steps:
        - uses: our/custom-action@v1
          with:
            mysecondinput: {{secrets.SOME_REQUIRED_SECRET}}

🤔Interesting! We simply use the uses keyword in the workflow file to specify that we are passing data as input to the desired action. In our example, since myfirstinput wasn't required we chose to not supply it with a value. This results in the default value being used. However we did supply a value for mysecondinput since it is a required input and has no default value.

Although most actions supply example on how to use them in their README file, some option may not be immediately documented. You can ALWAYS find what values and action expects or allows by reading the `action.yml` file for that action. This is a good habit to get into