Pipeline validation fails with Unexpected value 'steps' in acr-login.yaml. Even I tribble-checked the docs and stackoverflows, I can't find the issue in my pipeline:
pipeline.yaml
trigger: none
pool:
name: MyPool
variables:
- template: vars/global.yaml
- template: vars/stage.yaml
stages:
- stage: Import
jobs:
- template: steps/acr-login.yaml
parameters:
registry_name: ${{variables.registry_name}}
acr-login.yaml
parameters:
- name: registry_name
type: string
steps:
- bash: |
az login --identity --output none
az acr login --name ${{ parameters.registry_name }} --output none
Your acr-login.yaml must contain (one or multible) jobs since you are using it as job template:
parameters:
- name: registry_name
type: string
jobs:
- job: myStep
steps:
- bash: |
az login --identity --output none
az acr login --name ${{ parameters.registry_name }} --output none
Related
In Azurce DevOPS I have a REST API defined in Environment and I have a yaml pipline that sets a variable. I want to pass this variable to the REST API but it does not work. I can get it to work fine in a Release Pipeline.
The REST API is used as a gate in Environment.
This is the URL and Parameters in the REST API servicenowchecker/api/ServiceNow/GetServiceNowChangeStatus/$(PipelineChangeNumber)?onlyDate=true and my problem is to get the content of $(PipelineChangeNumber) to work. I cannot fin out how it has to be written in URL and Parameters section
my yaml pipeline looks like this - can someone please help me out - thanks
name: Test_serviceNowCheker-$(Date:yyyyMMdd)$(Rev:.r)
trigger: none
variables:
name: PipelineChangeNumber
value: CHG0070534
stages:
stage: Stage1
jobs:
deployment:
pool:
name: dotNET
environment:
name: P1_Urgent_CRB_Environment
job: Say_Hello
pool:
name: dotNEt
steps:
task: PowerShell#2
displayName: Hello from stage1
inputs:
targetType: 'inline'
script:
write-host "Hello from stage 1";
task: PowerShell#2
displayName: Set Outputvar OutPutCase
inputs:
targetType: 'inline'
script: Write-Host "##vso[task.setvariable variable=ChangeNumber;isoutput=true]CHG0070534";
name: OutPutCase
powershell: |
write-host "OutPutCase.ChangeNumber = $(OutPutCase.ChangeNumber)";
write-host "PipelineChangeNumber = $(PipelineChangeNumber)";
stage: Stage2
dependsOn: Stage1
variables:
Stage2_ChangeNumber: $[ stageDependencies.Stage1.Say_Hello.outputs['OutPutCase.ChangeNumber'] ]
jobs:
deployment:
pool:
name: DotNet
environment:
name: P1_Urgent
job: Say_Hello_again
pool:
name: DotNet
steps:
task: PowerShell#2
displayName: Hello from stage2
inputs:
targetType: 'inline'
script:
write-host "Hello from stage 2";
write-host "Stage2_ChangeNumber = $(Stage2_ChangeNumber)";
write-host "PipelineChangeNumber = $(PipelineChangeNumber)";
I have tried to write the as $(PipelineChangeNumber) and $[ $(PipelineChangeNumber) ] then the REST API does not work at all.
When it is written as $[ $PipelineChangeNumber ] the REST API starts up but is sending https://XXXXXX-xx/servicenowchecker/api/ServiceNow/GetServiceNowChangeStatus/$[ $PipelineChangeNumber ]?onlyDate=true and the ¤PipelineChangeNumber is null.
I am writing an azure pipeline yml requesting to pass variables between jobs but the variables are not passing through. however, it wasn't successful and it returns an empty variable.
here is my pipeline:
jobs:
- job: UpdateVersion
variables:
terraformRepo: ${{ parameters.terraformRepo }}
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
persistCredentials: true
- checkout: ${{ parameters.terraformRepo }}
- task: AzureCLI#2
displayName: PerformVerUpdate
inputs:
azureSubscription: ${{ parameters.azureSubscriptionName }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
echo Step 3 result
echo "Reponame $Reponame"
echo "notify $notify"
echo "pullRequestId $pullRequestId"
echo "##vso[task.setvariable variable=pullRequestId;isOutput=true;]$pullRequestId"
echo "##vso[task.setvariable variable=Reponame;isOutput=true;]$Reponame"
echo "##vso[task.setvariable variable=notify;isOutput=true;]true"
Name: PerformVerUpdate
- job: SlackSuccessNotification
dependsOn: UpdateVersion
condition: and(succeeded(), eq(dependencies.UpdateVersion.outputs['PerformVerUpdate.notify'], 'true'))
pool:
vmImage: 'ubuntu-latest'
variables:
- group: platform-alerts-webhooks
- name: notify_J1
value: $[ dependencies.UpdateVersion.outputs['PerformVerUpdate.notify'] ]
- name: pullRequestId_J1
value: $[ dependencies.UpdateVersion.outputs['PerformVerUpdate.pullRequestId'] ]
- name: Reponame_J1
value: $[ dependencies.UpdateVersion.outputs['PerformVerUpdate.Reponame'] ]
steps:
- task: AzurePowerShell#5
displayName: Slack Notification
inputs:
pwsh: true
azureSubscription: ${{ parameters.azureSubscriptionName }}
ScriptType: 'InlineScript'
TargetAzurePs: LatestVersion
inline: |
write-host "Reponame $(Reponame_J1)"
write-host "pullRequest $(pullRequestId_J1)"
I've tried so many different syntax for it but the variables are still not able to pass through between both jobs - e.g. The condition is passing Null result to second job "(Expanded: and(True, eq(Null, 'true'))". Could anyone help with this?
Firstly 'Name' should be 'name' in lowercase
Name: PerformVerUpdate
The rest of syntax seems fine(I have tested it on Bash task because I do not have Azure subscription).
If renaming 'Name' does not help I suppose the problem may be that your Bash task is running within AzureCLI#2 task.
Maybe as workaround you could add new Bash task right after AzureCLI#2 and try to set there output variable for next job?
Following is how our.drone.yml looks like (and template also listed below) this an example configuration very much how we want in our production. The reason we are using a template is that our staging and production have similar configurations with values different in them(hence circuit template). And we wanted to remove duplication using the template circuit.yaml.
But currently, we are unable to do so df I don’t define the test.yaml(template) and have test step imported without template (and have the circuit template define to avoid the duplicate declaration of staging and production build) the drone build fails with
"template converter: template name given not found
If I define the test step as a template. I see the test step working but on creating the tag I see the following error
{"commit":"28ac7ad3a01728bd1e9ec2992fee36fae4b7c117","event":"tag","level":"info","msg":"trigger: skipping build, no matching pipelines","pipeline":"test","ref":"refs/tags/v1.4.0","repo":"meetme2meat/drone-example","time":"2022-01-07T19:16:15+05:30"}
---
kind: template
load: test.yaml
data:
commands:
- echo "machine github.com login $${GITHUB_LOGIN} password $${GITHUB_PASSWORD}" > /root/.netrc
- chmod 600 /root/.netrc
- go clean -testcache
- echo "Running test"
- go test -race ./...
---
kind: template
load: circuit.yaml
data:
deploy: deploy
create_tags:
commands:
- echo "Deploying version $DRONE_SEMVER"
- echo -n "$DRONE_SEMVER,latest" > .tags
backend_image:
version: ${DRONE_SEMVER}
tags:
- '${DRONE_SEMVER}'
- latest
And the template is below
test.yaml
kind: pipeline
type: docker
name: test
steps:
- name: test
image: golang:latest
environment:
GITHUB_LOGIN:
from_secret: github_username
GITHUB_PASSWORD:
from_secret: github_token
commands:
{{range .input.commands }}
- {{ . }}
{{end}}
volumes:
- name: deps
path: /go
- name: build
image: golang:alpine
commands:
- go build -v -o out .
volumes:
- name: deps
path: /go
volumes:
- name: deps
temp: {}
trigger:
branch:
- main
event:
- push
- pull_request
circuit.yaml
kind: pipeline
type: docker
name: {{ .input.deploy }}
steps:
- name: create-tags
image: alpine
commands:
{{range .input.create_tags.commands }}
- {{ . }}
{{end}}
- name: build
image: plugins/docker
environment:
GITHUB_LOGIN:
from_secret: github_username
GITHUB_PASSWORD:
from_secret: github_token
VERSION: {{ .input.backend_image.version }}
SERVICE: circuits
settings:
auto_tag: false
repo: ghcr.io/meetme2meat/drone-ci-example
registry: ghcr.io
To reduce duplicates I want to rewrite our Azure DevOps pipelines. The main pipelines looks like:
parameters:
- name: MODULE_Foo
type: boolean
default: false
- name: MODULE_Bar
type: boolean
default: false
...
- name: MODULE_X
type: boolean
default: false
...rest of parameters
- name: BRANCH_NAME
type: string
- name: CHECKOUT_TAG
type: boolean
default: false
extends:
template: template1.yml
parameters:
MODULES: ${{paramaters}}
BRANCH_NAME: ${{parameters.BRANCH_NAME}}
...rest of parameters
The template template1.yml:
parameters:
- name: MODULES
type: object
default: {}
...rest of parameters
stages:
- stage: Build
jobs:
- job: BuildAndDeploy
steps:
- bash: |
MODULES=$(echo "${{ convertToJson(parameters.MODULES) }}" \
| sed -E 's/^([[:space:]]+)/\1"/;s/(:[[:space:]]+)/"\1"/;s/,$/",/;s/([^{},])$/\1"/' \
| jq 'with_entries( select(.key | startswith("MODULE_") ) )' \
)
echo "##vso[task.setvariable variable=MODULES;]$MODULES"
- template: template2.yml
parameters:
MODULES: $(MODULES)
...rest of parameters
And finally template2.yml:
parameters:
- name: MODULES
type: object
default: {}
...rest of parameters
- ${{ each module in parameters.MODULES }}:
- ${{ if and(startsWith(module.Key, 'module'), eq(module.Value, true)) }}:
- bash: |
echo "Module to build: ${{module.key}}, Value: ${{module.value}}"
Now I'm stuck.
How to pass a variable as parameter to a template?
To the template is passed empty string '' for ${{variables.MODULES}} or '$(MODULES)' for $(MODULES). But never generated string. I think that $(MODULES) is valid for this situation.
How to create a valid object, which can be iterated inside each loop in template?
I think that my construction with convertToJson, sed, and jq is not correct.
My goal is to eliminate the MODULE_ parameter group from the templates. Currently, every template contains a duplicate of this parameter section.
I am trying to implement Github-actions(bot), which runs gradle test when PR has been created.
To assure that my workflow file works as I expected, I explicitly wrote a test method which should cause failure.
#Test
fun thisShouldFail() {
assertEquals(1, 2)
}
When I try testing on my local machine, I get the log below.
> Task :test FAILED
FAILURE: Build failed with an exception.
# More
Above log indicates that there was something wrong in the test codes as I expected it to be.
But then Github actions bot runs this command, the test code result is SUCCESS.
Below is my github workflow yaml file for this action.
name: PullRequestGradleTest
on:
pull_request_target:
types: [labeled]
jobs:
test:
name: GradleTest
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'STAGING')
steps:
- name: checkout
uses: actions/checkout#v2
- name: Setup JDK 1.8
uses: actions/setup-java#v2
with:
java-version: '8'
distribution: 'adopt'
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Test
run: gradle test --tests "*"
- name: Test Success
if: success()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "All tests passed.",
event: "APPROVE"
})
- name: Test Fail
if: failure()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "There is something wrong with test codes.",
event: "REQUEST_CHANGES"
})
await github.pulls.update({
...context.repo,
pull_number,
state: "closed"
})
I found that you are using gradle, not gradlew.
name: PullRequestGradleTest
on:
pull_request_target:
types: [labeled]
jobs:
test:
name: GradleTest
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'STAGING')
steps:
- name: checkout
uses: actions/checkout#v2
- name: Setup JDK 1.8
uses: actions/setup-java#v2
with:
java-version: '8'
distribution: 'adopt'
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Test
run: ./gradlew test --tests "*"
- name: Test Success
if: success()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "All tests passed.",
event: "APPROVE"
})
- name: Test Fail
if: failure()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "There is something wrong with test codes.",
event: "REQUEST_CHANGES"
})
await github.pulls.update({
...context.repo,
pull_number,
state: "closed"
})
If you use gradle in the command, it will depend on the machine's environment. In this case, there is a possibility that occurs error because of Gradle version. Therefore, you need to use the project's Gradle which is included with your repo. The way to use is using gradlew scripts.
I also recommend following these three steps to test the branch for the pull request.
Clean -> Assemble(or build) -> Test
Base problem was that if we use pull_request_target event, the action runs on the target branch, which would be the base branch that the PR will be merged into. To solve this problem, I had to explicitly set where this action will run on.
On job => steps
steps:
- name: checkout
uses: actions/checkout#v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name }}