Inside Github Action I'm using Anchore+grype to scan a container image, using the job below:
name: "CI"
on:
push:
pull_request:
branches:
- main
jobs:
image-analysis:
name: Analyze image
runs-on: ubuntu-18.04
needs: build
steps:
- name: Scan operator image
uses: anchore/scan-action#v3
id: scan
with:
image: "qserv/qserv-operator:2022.1.1-rc1"
acs-report-enable: true
In order to ignore a false-positive during image scan, I want to create the file $HOME/.grype.yaml (see content below) before launching the image scan:
ignore:
# False positive, see https://github.com/anchore/grype/issues/558
- vulnerability: CVE-2015-5237
fix-state: unknown
package:
name: google.golang.org/protobuf
version: v1.26.0
type: go-module
location: "/manager"
Could you please show me how to create this file inside Github Action?
you could do something as simple as creating the file and then writing to it like this:
- name: Create grype.yaml
run: |
touch grype.yaml
echo "
ignore:
# False positive, see https://github.com/anchore/grype/issues/558
- vulnerability: CVE-2015-5237
fix-state: unknown
package:
name: google.golang.org/protobuf
version: v1.26.0
type: go-module
location: "/manager"" > ~/grype.yaml
This one works and has been tested successfully on Github Actions:
name: "CI"
on:
push:
pull_request:
branches:
- main
jobs:
image-analysis:
name: Analyze image
runs-on: ubuntu-18.04
permissions:
security-events: write
needs: build
steps:
- name: Create grype configuration
run: |
cat <<EOF > $HOME/.grype.yaml
ignore:
# False positive, see https://github.com/anchore/grype/issues/558
- vulnerability: CVE-2015-5237
fix-state: unknown
package:
name: google.golang.org/protobuf
version: v1.26.0
type: go-module
location: "/manager"
EOF
- name: Scan operator image
uses: anchore/scan-action#v3
id: scan
with:
image: ""qserv/qserv-operator:2022.1.1-rc1""
acs-report-enable: true
fail-build: false
Related
Are there any variables in Azure which I can use to get the name of the source folder(repository name). I tried using Build.SourcesDirectory and System.DefaultWorkingDirectory , both returned /Users/runner/work/1/s. I expect to get MyProjectFolderName which is the source directory of my project in github.
If you checkout self repo(This is default situation), then just follow Daniel's suggestion is ok:
$(Build.Repository.Name)
yml file like this:
trigger:
- none
pool:
vmImage: ubuntu-latest
steps:
- task: PythonScript#0
inputs:
scriptSource: 'inline'
script: |
str = "$(Build.Repository.Name)"
str.split("/")
#get the last name
print(str.split("/")[-1])
If you only checkout one repo and not check out self, then just use below yml:
trigger:
- none
pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: 222
type: github
name: xxx/222
endpoint: xxx
- repository: 333
type: github
name: xxx/333
endpoint: xxx
variables:
- name: checkoutreporef
value: $[ resources.repositories['333'].name ]
steps:
- checkout: 333
- task: PythonScript#0
inputs:
scriptSource: 'inline'
script: |
str = "$(checkoutreporef)"
str.split("/")
#get the last name
print(str.split("/")[-1])
If you checkout two and more repo, below yml will help you get the repo names:
trigger:
- none
pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: 222
type: github
name: xxx/xxx
endpoint: xxx
- repository: 333
type: github
name: xxx/xxx
endpoint: xxx
steps:
- checkout: 222
- checkout: 333
- task: PythonScript#0
inputs:
scriptSource: 'inline'
script: |
import os
#get current sub folders name
def getfoldersname():
folders = [f for f in os.listdir('.') if os.path.isdir(f)]
return folders
#print each folder name
def printfoldersname():
for folder in getfoldersname():
print(folder)
printfoldersname()
I currently have the following pipeline working:
schedules:
- cron: "0 20 * * FRI"
displayName: 'Weekly Run'
always: true
branches:
include:
- 'develop'
trigger: none
variables:
DEPENDABOT_EXTRA_CREDENTIALS: '[{"type":"npm_registry","token":"$(DEPENDABOT_PAT)","registry":"SOME_URL"}]' # put the credentials for private registries and feeds
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: CheckDependencies
displayName: 'Check Dependencies'
jobs:
- job: Dependabot
displayName: 'Run Dependabot'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: dependabot#1
displayName: 'Run Dependabot - npm'
inputs:
useConfigFile: false
packageManager: 'npm'
setAutoComplete: false
azureDevOpsAccessToken: $(DEPENDABOT_PAT) # env variable
gitHubAccessToken: $(GITHUB_TOKEN) # env variable
targetBranch: 'develop'
openPullRequestsLimit: 15
However, it has started given the following warning:
"Using explicit inputs instead of a configuration file will be deprecated in the next minor release.
Migrate to using a config file at .azuredevops/dependabot.yml or .github/dependabot.yml."
I have added the config file per the docs: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#configuration-options-for-private-registries
with my config file looking like this:
version: 2
registries:
npm-reg:
type: npm-registry
url: https://pkgs.dev.azure.com/BC-SDPR-Research/_packaging/Research/npm/registry/
token: ${{secrets.AZURE_ACCESS_TOKEN}}
updates:
- package-ecosystem: "npm"
directory: "/"
registries:
- npm-reg
schedule:
interval: "weekly"
day: "Friday"
time: "20:00"
timezone: "America/Los_Angeles"
open-pull-requests-limit: 15
setAutoComplete: false
azureDevOpsAccessToken: ${{secrets.AZURE_ACCESS_TOKEN}}
gitHubAccessToken: ${{secrets.GITHUB_TOKEN}}
targetBranch: 'develop'
openPullRequestsLimit: 15
I have tried everything, and I am still getting the error:
Dependabot::Clients::Azure::Forbidden (Dependabot::Clients::Azure::Forbidden)
This is likely generated due to authentication with my npm registry.
Any help would be greatly appreciated.
Thanks
Based on this post and on this Github issue comment, we can't use the token property but instead the username&password properties, with the PAT token used as a password
registries:
npm-reg:
type: npm-registry
url: https://pkgs.dev.azure.com/<org>/<id>/_packaging/<feed-name>/npm/registry/
username: <username> # I am not 100% sure that this value HAS to match the PAT...
password: ${{secrets.DEVOPS_PAT}} # this is the non-base64 encoded PAT
This is part of my Yml file
I need to re-call this template if it failed.it should be rerun again. After a few seconds, ideally.I am new to yml files
I tried to use retryCountOnTaskFailure but it should be under task but the template calling different hierarchy
https://learn.microsoft.com/en-us/azure/devops/release-notes/2021/sprint-195-update#automatic-retries-for-a-task
- template: ${{variables['System.DefaultWorkingDirectory']}}
parameters:
Test: ${{ parameters.isTestRelease }}
Environment: ${{ parameters.deploymentTarget }}
Component: '${{ parameters.component }}'
The retryCountOnTaskFailure feature is applied to individual tasks within a pipeline. Templates aren't tasks, they act more like an include that expands the contents of the template into your pipeline.
# pipeline.yml
trigger: none
parameters:
- name: isTestRelease
type: boolean
default: false
- name: deploymentTarget
type: string
default: DEV
values:
- DEV
- QA
- UAT
- PROD
- name: component
type: string
default: 'x'
stages:
- template: my-template.yml
parameters:
Test: ${{ parameters.isTestRelease }}
Environment: ${{ parameters.deploymentTarget }}
Component: ${{ parameters.component }}
And within the template, you'd want to add the retry logic to specific tasks:
# my-template.yml
parameters:
- name: isTestRelease
type: boolean
- name: component
type: string
stages:
- stage: Test
jobs:
- job: 1
steps:
- task: ...
- task: ...
- task: ...
retryCountOnFailure: 2
- task: ...
It's also located under "Control Options" when the "Command Line" task is added:
I am trying to create a pipeline in concourse, which is going to trigger on github updates on a remote branch, and use that branch to plan, apply and destroy a terraform deployment.
- name: terraform-repo
type: git
icon: github
source:
uri: https://github.com/....
#docker image
- name: terraform-0-13-7
type: registry-image
source:
repository: hashicorp/terraform
tag: 0.13.7
jobs:
- name: terraform-deplyoment
plan:
- get: terraform-0-13-7
- get: terraform-repo
trigger: true
- task: terraform-init
image: terraform-0-13-7
config:
inputs:
- name: terraform-repo
outputs:
- name: terraform-repo
platform: linux
run:
path: terraform
dir: terraform-repo
args:
- init
- task: terraform-plan
image: terraform-0-13-7
config:
inputs:
- name: terraform-repo
outputs:
- name: terraform-repo
platform: linux
run:
path: terraform
dir: terraform-repo
args:
- plan
params:
variable1: "test"
variable2: "test2"
This is erroring out on the concourse GUI when triggering the pipeline mentioning that the vars are not available. Am I doing something wrong with the syntax?
The params are exposed to the task as environment variables so you should use them as input variables
- task: terraform-plan
image: terraform-0-13-7
config:
inputs:
- name: terraform-repo
outputs:
- name: terraform-repo
platform: linux
run:
path: terraform
dir: terraform-repo
args:
- plan
params:
TF_VAR_variable1: "test"
TF_VAR_variable2: "test2"
Need a small help , can someone point me what is the issue here .
What i am trying to achieve , the pipeline has to run checkout irrespective of the branch i am in , but in the build stage if the pipeline run from master it has execute some templet if from other branch different templet , i tried many option no luck .
Any pointer much appreciated .
- name: release
displayName: ReleaseVersion
type: string
default: ' '
- name: Deployment
displayName: DeploymentVersion
type: string
default: ' '
- name: Library
displayName: Library Release
type: boolean
default: True
trigger:
- none
pool:
name: DOTAzure-Ubuntu-20.04
resources:
repositories:
- repository: azureTemplates
type: githubenterprise
name: AAAAA/azure-pipelines
endpoint: BBBBBB
# You should add below variables to work complete pipeline
variables:
- name: servicename
value: XXXXX
- name: countryCode
value: YYYYY
- name: targetPort
value: 8113
stages:
- stage: Checkout
displayName: Micro Service checkout and Secrets
jobs:
- job:
steps:
- template: templates/repocheckout.yml#azureTemplates
- template: templates/retrieving_secrets.yml#azureTemplates
- template: templates/Ingesting_secrets.yml#azureTemplates
- stage: Build
displayName: Microservice Build
jobs:
- job: Master
condition: eq(variables['Build.SourceBranchName'], 'master')
steps:
- template: templates/mavenbuild_new.yml#azureTemplates
- template: templates/push_artifact_jfrog.yml#azureTemplates
parameters:
service_name: '$(countryCode)-$(servicename)'
release_version: $(release)
- job: Develop
dependsOn: Master
condition: eq(variables['Build.SourceBranchName'], 'develop')
steps:
- template: templates/mavenbuild.yml#azureTemplates
- template: templates/push_artifact_jfrog.yml#azureTemplates
parameters:
service_name: '$(countryCode)-$(servicename)'
release_version: $(release)
This doesn't look like valid yaml.
Have a look at this: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema
It looks like you are missing this at the top of the file:
stages:
i.e. your yaml should be:
stages:
- stage: Checkout
displayName: Micro Service checkout and Secrets
jobs:
etc