How to send github action artifact in a slack notification - slack-api

I'm trying to send customized slack notifications about the status of github action workflows. I've built my custom messages with the help of https://github.com/8398a7/action-slack integration.
However, I'm trying to send the github action artifact that is generated with each workflow to my slack channel. Is that something that can be done?
Below is the yaml file that I'm using:
...
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
smoke-test:
runs-on: ubuntu-latest
container:
image: dannydainton/htmlextra
steps:
- name: Cloning Repository
id: initializing
uses: actions/checkout#master
- name: Executing API test suite
run: newman run "postman_collection.json" --environment "postman_environment.json" --reporters cli,htmlextra --reporter-htmlextra-export report.html
- if: failure()
uses: actions/upload-artifact#v2
id: generating-report
with:
name: reports
path: report.html
- uses: 8398a7/action-slack#v3
with:
status: custom
custom_payload: |
{
text: "Test Execution Passed",
attachments: [{
color: 'good',
text: `Test Execution for ${process.env.AS_WORKFLOW} workflow has SUCCEEDED! :heavy_check_mark:`,
fields: [{
title: "Test Type",
value: 'Smoke Test',
short: false
},
{
title: "Overall APIs Status",
value: "Healthy :heavy_check_mark:",
short: false
},
{
title: "Repository",
value: `${process.env.AS_REPO}`,
short: false
},
{
title: "Author",
value: `${process.env.AS_AUTHOR}`,
short: false
},
{
title: "Execution Time",
value: `${process.env.AS_TOOK}`,
short: false
},
{
title: "Number of Requests",
value: '39',
short: true
},
{
title: "Number of Assertions",
value: '64',
short: true
}]
}]
}
if: success()
- uses: 8398a7/action-slack#v3
if: failure()
with:
status: custom
custom_payload: |
{
text: 'Test Execution Failed :siren_alert::siren_alert:',
attachments: [{
color: 'danger',
text: `Test Execution for ${process.env.AS_WORKFLOW} workflow has FAILED! :x:`,
fields: [{
title: "Test Type",
value: 'Smoke Test',
short: true
},
{
title: "Repository",
value: `${process.env.AS_REPO}`,
short: true
},
{
title: "Author",
value: `${process.env.AS_AUTHOR}`,
short: false
}],
actions: [{
name: "report",
text: "View Report",
type: "button",
value: `https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}`
}]
}]
}
So I need to pass the artifact to the step which sends a slack notification on failure.
Thanks

Related

conditionalize Parameter in Jenkins

we are trying to parameter below code
If choice = dev and Method = post then show SITE_ID as an input
else show SITE_ID,CUSTOMER_ID,REGION,PLATFORM_ACCOUNT_ID,PLATFORM_TYPE as an input
right now it is showing all columns SITE_ID,CUSTOMER_ID,REGION,PLATFORM_ACCOUNT_ID,PLATFORM_TYPE independent of choice selection
pipeline {
parameters {
choice(
name: 'STAGE',
choices: ['dev', 'stable', 'preprod'],
description: 'The environment name (will not allow deploy on prod)'
)
choice(
name: 'METHOD',
choices: ['post', 'delete'],
description: 'Method name'
)
string(
name: 'SITE_ID', trim: true,
description: 'Please provide SITE_ID'
)
string(
name: 'CUSTOMER_ID', trim: true,
description: 'Please provide CUSTOMER_ID'
)
string(
name: 'REGION', trim: true,
description: 'Please provide REGION'
)
string(
name: 'PLATFORM_ACCOUNT_ID', trim: true,
description: 'Please provide PLATFORM_ACCOUNT_ID'
)
string(
name: 'PLATFORM_TYPE', trim: true,
description: 'Please provide PLATFORM_TYPE'
)
}
}

Bitbucket Failed to persist entry: API_ERROR: Branch not found

The website is built using Gatsby with Netlify CMS in Bitbucket. The error shows when I tried to change something on the custom page using the Netlify CMS (Live), but works perfectly on the local setup. This confuses me and I don't know what and why is that happening.
Here's my config.yml
backend:
name: bitbucket
repo: repo-name
branch: master
auth_type: implicit
app_id: app-id
commit_messages:
create: "Create {{collection}} “{{slug}}”"
update: "Update {{collection}} “{{slug}}”"
delete: "Delete {{collection}} “{{slug}}”"
uploadMedia: "[skip ci] Upload “{{path}}”"
deleteMedia: "[skip ci] Delete “{{path}}”"
local_backend: true
publish_mode: editorial_workflow
media_folder: static/img
public_folder: /img
(Skipped some because it is too long but here is the setup of the custom page)
- name: "pages"
label: "Pages"
label_singular: "Page"
create: true
files:
- file: "src/pages/resources/i-mop-xl-operator-resources.md"
label: "i-mop xl operator resources"
name: "i-mop xl operator resources"
fields:
- {
label: "Template Key",
name: "templateKey",
widget: "hidden",
default: "i-mop-xl-operator-resources",
}
- { label: Title, name: title, widget: string }
- { label: Heading, name: heading, widget: string }
- { label: Description, name: description, widget: string }
- {
label: "Seo Description",
name: "seodescription",
widget: "string",
}
- { label: "Seo Keyword", name: "seokeyword", widget: "string" }
- {
label: "Seo Title",
name: "seotitle",
widget: "string",
required: false,
}
And the error is saying
P.S this is only happening on the new pages that I've created.
So I've found the solution to this and I think it is pretty simple. The name should not have a blank space.
From this:
- file: "src/pages/resources/i-mop-xl-operator-resources.md"
label: "i-mop xl operator resources"
name: "i-mop xl operator resources"
To this:
- file: "src/pages/resources/i-mop-xl-operator-resources.md"
label: "i-mop xl operator resources"
name: "i-mop-xl-operator-resources"

Jenkins pipeline input script with one prompt only

Don't need 2 prompt in Jenkins pipeline with input script. In snippet, there is highlighted 1 and 2 where pipeline prompt 2 times for user input.
If execute this pipeline, prompt 1 will provide user to "Input requested" only, so no option to "Abort". Prompt 2 is okay as it ask to input the value and also "Abort" option.
Prompt 1 is almost useless, can we skip promt this and directly reach to prompt 2?
pipeline {
agent any
parameters {
string(defaultValue: '', description: 'Enter the Numerator', name: 'Num')
string(defaultValue: '', description: 'Enter the Denominator', name: 'Den')
}
stages {
stage("foo") {
steps {
script {
if ( "$Den".toInteger() == 0) {
echo "Denominator can't be '0', please re-enter it."
env.Den = input message: 'User input required', ok: 'Re-enter', // 1-> It will ask whether to input or not
parameters: [string(defaultValue: "", description: 'Enter the Denominator', name: 'Den')] // 2-> It will ask to input the value
}
}
sh'''#!/bin/bash +x
echo "Numerator: $Num\nDenominator: $Den"
echo "Output: $((Num/Den))"
'''
}
}
}
}
Yes, you can simplify the input by using $class: 'TextParameterDefinition'.
e.g.
pipeline {
agent any
parameters {
string(defaultValue: '', description: 'Enter the Numerator', name: 'Num')
string(defaultValue: '', description: 'Enter the Denominator', name: 'Den')
}
stages {
stage("foo") {
steps {
script {
if ( "$Den".toInteger() == 0) {
env.Den = input(
id: 'userInput', message: 'Wrong denominator, give it another try?', parameters: [
[$class: 'TextParameterDefinition', defaultValue: '', description: 'Den', name: 'den']
]
)
}
}
sh'''#!/bin/bash +x
echo "Numerator: $Num\nDenominator: $Den"
echo "Output: $((Num/Den))"
'''
}
}
}
}
If you want to go the extra mile and ask for both values:
def userInput = input(
id: 'userInput', message: 'Let\'s re-enter everything?', parameters: [
[$class: 'TextParameterDefinition', defaultValue: '', description: 'Denominator', name: 'den'],
[$class: 'TextParameterDefinition', defaultValue: '', description: 'Numerator', name: 'num']
]
)
print userInput
env.Den = userInput.den
env.Num = userInput.num

JHipster yeoman repeating prompt based on option selected

Suppose I want to prompt the user to select among a list of database options with "type checkbox":
{
type: 'checkbox',
name: 'databaseType',
message: `Which ${chalk.yellow('*type*')} of database(s) would you like to use?`,
choices: response => {
const databaseOpts = [
{
value: 'mysql',
name: 'MySQL'
},
{
value: 'cassandra',
name: 'Cassandra'
},
{
value: 'mongodb',
name: 'MongoDB'
}
];
return databaseOpts;
},
default: 0
},
After this initial prompt, I want to get the response for whichever option(s) they selected and prompt them again for the name of the database based on their selection(s) then store them:
{
when: response => response.databaseType === 'mysql',
type: 'input',
name: 'selectedMySQL',
message: 'What is the name of your mysql database? ',
default: 'testmysql',
store: true
},
{
when: response => response.databaseType === 'cassandra',
type: 'input',
name: 'selectedCassandra',
message: 'What is the name of your cassandra database? ',
default: 'testcassandra',
store: true
},
{
when: response => response.databaseType === 'mongo',
type: 'input',
name: 'selectedMongo',
message: 'What is the name of your mongo database? ',
default: 'testmongo',
store: true
}
Sample Desired Output:
For example user's choices in databaseOpts: {mysql, mongodb}
It will then ask:
1) What is the name of your mysql database?:
2) What is the name of your mongo database?:
User enters the name(s) respectively which will be stored in selectedMySQL and selectedMongo.
I'm unfamiliar with yeoman syntax, but this is the logic I want to implement. Please help, Thanks.
I tried:
when: response => response.databaseType.databaseOpts === 'mysql'
but it's still skipping the response prompts.

Sending PR id and other info with Bitbucket Cloud webhooks

I am looking at the docs for webhooks for Bitbucket Cloud:
https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html
I can send a GET request to the url in the url field, but I want to send the commit of the branch that changed, or the PR id, so that I can send a request back to Bitbucket to update Bitbucket's UI. Is there a way to include dynamic values in the url field in the webhooks form?
Bitbucket will send the info for you in the request body, not in query params, it looks like this:
{ push: { changes: [ [Object] ] },
actor:
{ username: 'ntrs_oleg',
display_name: 'Foo',
uuid: '{c0e09bb2-26e-f89afe7b1b2c}',
links: { self: [Object], html: [Object], avatar: [Object] },
nickname: 'interos_alex',
type: 'user',
account_id: '5cc0db15c66f0ffe44c597' },
repository:
{ scm: 'git',
website: '',
name: 'jenkins-jobs',
links: { self: [Object], html: [Object], avatar: [Object] },
project:
{ key: 'DEVOPS',
type: 'project',
uuid: '{2dc188bd997eaa244d9}',
links: [Object],
name: 'devops' },
full_name: 'interos/jenkins-jobs',
owner:
{ username: 'interos',
display_name: 'Interos',
type: 'team',
uuid: '{d4ee7ec3-04fce894572}',
links: [Object] },
type: 'repository',
is_private: true,
uuid: '{4c6795ff-362eb64d935b9}' } }

Resources