I am new to GitHub actions and for a few days I have been trying to set up a simple action workflow. I tried searching everywhere about the errors, went through some action workflow syntax documentation by GitHub but still I am not able to figure out anything.
I am trying to use this action template: https://github.com/marketplace/actions/jelastic-github-actions
I just copied and pasted the sample code given in the repo and filled in necessary values but there is always at least one error that keeps popping up.
What is wrong with the yml syntax below (this is exact sample code):
- name: Run GetEnv command
uses: abhisek91/github-actions-jelastic#master
with:
jelastic_url: app.mycloud.by
jelastic_username: ${{ secrets.JELASTIC_USERNAME }}
jelastic_password: ${{ secrets.JELASTIC_TOKEN }}
task: environment/control/getenvs
Github is showing me Invalid type found: object was expected but an array was found for the above code and I don't know what it means.
Related
I've been trying to set up the most basic GitHub action that can be triggered via API, and I managed to trigger it, but now I'm having trouble passing down the "inputs" and using them in the jobs...
I tried reading the documentation and all, and it should work but I'm probably missing some syntax or something...
Here's the action code:
name: Test
on:
repository_dispatch:
inputs:
body:
default: 'testdefaultvalue'
description: 'Test desc'
required: true
jobs:
print_inputs:
runs-on: ubuntu-latest
steps:
- name: Print inputs
run: echo "The inputs are ${{ inputs.body }}"
And here's the body that I'm trying to send using POST which hits and triggers this action
{"event_type": "my_event", "client_payload": {"body": "Hello, world!"}}
I keep getting only the first part of the echo, like on this screenshot
I even tried just printing out the inputs body with the default value using a different kinds of syntaxes but nothing worked. Hopefully, this is not a duplicate and someone will help me and it'll be useful for someone in the future as well!
According to repository_dispatch, you need to refer to the complete event context to get the values.
So, this should work in your case:
echo ${{ github.event.client_payload.body }}
My goal is actually pretty easy but I am not sure if it is possible in the Github Actions or not. So I have an action file that is used for deployment of different Azure subscription/tenants. So I have different AZURE_CREDENTIALS for every one of them.
For example AZURE_CREDENTIALS_NUM1 is one of them. I am giving the name of NUM1 as a customer name to the script in a config file but I do not want to change everywhere in the script that use the same secret. I try this approach but it didn't work:
- uses: azure/login#v1
with:
creds: ${{ "${{needs.Parameters.outputs.azureCredentials}}" }}
Inside the needs.Parameters.outputs.azureCredentials part, I created name for AZURE_CREDENTIALS_NUM1 but this syntax is not accepted by Github Actions.
You need to add mask as below:
- name: Add mask
run: |
echo "::add-mask::${{needs.Parameters.outputs.azureCredentials}}"
- uses: azure/login#v1
with:
creds: ${{needs.Parameters.outputs.azureCredentials}}
Then it will be masked in logs. For more details please check here
when this step is running echo "::add-mask::${{needs.Parameters.outputs.azureCredentials}}"
this value will be printed in the logs "${{needs.Parameters.outputs.azureCredentials}}"
if ${{needs.Parameters.outputs.azureCredentials}}="password" in the logs it will show as below echo "::add-mask::password" indirectly we can see the creds in the logs!!
I oversee some teams, and one team has an Azure DevOps pipeline leveraging the YAML pipeline setup. Unfortunately, due to Covid-19, we have had to release a lot of staff, including the entire DevOps team. That has left my team with no DevOps knowledge and an established YAML pipeline that we're struggling to get acquainted with.
So far, we've make progress and have learned a lot. However, while trying to troubleshoot an IIS web site deployment task, we have had some trouble figuring out where some of the parameters passed to each stage are sourced from.
For example, a snippet from a template:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'Create Or Update IIS Website'
inputs:
EnableIIS: true
WebsiteName: ${{ parameters.WebsiteName }}
WebsitePhysicalPath: ${{ parameters.WebsitePhysicalPath }}
AddBinding: ${{ parameters.AddWebsiteBinding }}
**Bindings: ${{ parameters.WebsiteBindings }}**
CreateOrUpdateAppPoolForWebsite: ${{ parameters.CreateOrUpdateAppPoolForWebsite }}
AppPoolNameForWebsite: ${{ parameters.WebsiteName }}
DotNetVersionForWebsite: ${{ parameters.DotNetVersionForWebsite }}
PipeLineModeForWebsite: ${{ parameters.PipeLineModeForWebsite }}
AppPoolIdentityForWebsite: ${{ parameters.AppPoolIdentityForWebsite }}
AppPoolUsernameForWebsite: ${{ parameters.AppPoolUsernameForWebsite }}
"WebsiteBindings" is one that we're interested in ... and I can work back to where the template is being used, and see this:
WebsiteBindings: '$(DevOps:IISWebsiteBindings)'
Problem is - I want to see what is being passed in here, and I cannot seem to figure out where the above value comes from. I am sure the answer is simple, but none of us have any Azzure DevOps experience, and we're kind of stuck on this simple problem. Is there anything in the above syntax that can clue me in as to where the values are located?
Other areas in the pipeline are referencing Azure AppConfig Key/Value storage for config transforms, and there are some pipeline variables set, but none line up with any of the values I am looking for.
Can anyone provide any insight here? Thank you in advance.
Problem is - I want to see what is being passed in here, and I cannot
seem to figure out where the above value comes from.
You can add a powershell task and output these variables through Write-Host to see what is passed here . For example : Write-Host "$(parameters.WebsiteBindings)"
According to the syntax of ${{ parameters.WebsiteBindings }}, I speculate that this variable comes from the template parameters.
In a pipeline, template expression variables (${{ variables.var }}) get processed at compile time, before runtime starts. You can use template expression syntax to expand both template parameters and variables . Template expressions are designed for reusing parts of YAML as templates.
I have repo A that holds pipeline templates. Repo A has the following azure-template.yml:
# Repo A / azure-template.yml
stages:
- stage: ${{ variables.stageName }}
jobs:
- job:
steps:
- task:
A lot of the code in repo A that has the templates refers to variables in the following format:
${{ variables.variableName }}. The variable file is in a different folder in repo A. (e.g. variables/variables.yaml)
Now let's move to repo B. Repo B has my azure-pipeline.yml that needs to build from repo A:
# Repo B / azure-pipeline.yml
resources:
repositories:
- repository: templates
type: git
name: repoA
ref: refs/heads/develop
variables:
- template: variables/variables.yml#templates
stages:
- template: azure-template.yml#templates # Template reference
When I run azure-pipeline.yml, I get the following error:
An error occurred while loading the YAML build pipeline. The string must have at least one character. Parameter name: environmentName
That parameter is not one of mine. I don't have it declared or set anywhere. This tells me it is Azure specific but I have no idea where/why it's there or where it is even set.
How can I run a pipeline with a yaml template that refers to a
variables file in a different repo with Azure DevOps?
You're in correct direction, at least a working direction. It's supported to do that like what you've done above. About the error you got, I assume there could be something wrong with your yaml syntax. You can try following steps to locate the issue:
Copy the content of azure-template.yml and variables.yaml directly into azure-pipeline.yml file, and run the pipeline again to check if the issue persists.
In your Azure-pipeline.yml, specify the trigger and pool.
In azure-template.yml, try replacing the ${{ variables.stageName }} with hard-code value.
This is my first time to see this error message, but according to Parameter name: environmentName.You can also check if Release.EnvironmentName has valid value in one PS task. Hope it helps :)
My use case is I want to have a unique version number for artifacts per each build/run. With current tools like CircleCI, Travis, etc. there is a build number available which is basically a counter that always goes up. So, I can create version strings like 0.1.0-27. This counter is increased each time even for the same commit.
How can I do something similar with GitHub Actions? Github actions only offer GITHUB_SHA and GITHUB_REF.
GitHub Actions now has a unique number and ID for a run/build in the github context.
github.run_id : A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run.
github.run_number : A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run.
github.run_attempt : A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run.
ref: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
You can reference them in workflows like this:
- name: Output Run ID
run: echo ${{ github.run_id }}
- name: Output Run Number
run: echo ${{ github.run_number }}
- name: Output Run Attempt
run: echo ${{ github.run_attempt }}
I had the same problem and have just created an action to generate sequential build numbers. Use it like
- uses: einaregilsson/build-number#v1
with:
token: ${{secrets.github_token}}
In steps after that you'll have a BUILD_NUMBER environment variable. See more info about using the same build number for different jobs and more at https://github.com/einaregilsson/build-number/
UPDATE: There is now a $GITHUB_RUN_NUMBER variable built into GitHub Actions, so this approach is not needed anymore.
If you want a constant integer increment (1,2,3,4,5), I haven't found anything in the docs that you could use as such increment which is aware of how many times that particular action ran. There's two solutions I can think of:
Maintaining state on the repo: for example with a count.build file that uses the workflow ID and you increment it on build. This is my least favourite solution of the two because it adds other complexities, like it will itself trigger a push event. You could store this file somewhere else like S3 or in a Gist.
Using the Date: if you're not worried about sequence on the integer increment you could just use the current data and time, for example 0.1.0-201903031310 for Today at 13:10.
Regardless if you have Actions Beta Access, I would definitely feed this back to GitHub.
Hope it helps.
You can use GitVersion to generate incrementing versions from tags in Git. The PR at https://github.com/GitTools/GitVersion/pull/1787 has some details, but basically you can define this job:
- uses: actions/checkout#v1
- name: Get Git Version
uses: docker://gittools/gitversion:5.0.2-beta1-34-linux-debian-9-netcoreapp2.1
with:
args: /github/workspace /nofetch /exec /bin/sh /execargs "-c \"echo $GitVersion_MajorMinorPatch > /github/workspace/version.txt\""