I have a pipeline in GHA, one of the steps sends a multiline string created in a previous step "message" to a custom action "send mail" that I am writing.
- name: send mail
id: mail
uses: internal/send-mail#main
with:
subject: "{{ github.event.pull_request.tittle }}"
mail_body: "\n```\n${{ steps.message.outputs.stdout }}\n```\n"
The custom action receives the multiline value as input correctly but I facing an error while trying to assign it as env variable.
name: send mail action
inputs:
subject:
mail_body:
runs:
using: composite
steps:
- name: set env variables
shell: bash
run: |
echo "MAIL_SUBJECT=${{ inputs.subject }}" >> $GITHUB_ENV
echo "MAIL_BODY=${{ inputs.mail_body }}" >> $GITHUB_ENV
At this point, I get this error:
stty: 'standard input': Inappropriate ioctl for device
TERM environment variable not set
How could I keep the multiline value for MAIL_BODY in the custom GHA?
My goal is to read the MAIL_BODY variable from a python script and continue the flow.
I'm trying to create a YAML based pipeline that takes a parameter, then trigger the pipeline to run from a Azure DevOps REST API. I'm able to see the build gets queued, but the parameter was not overridden from my POST body.
My template my-template.yaml.
parameters:
- name: testParam
type: string
default: 'N/A'
steps:
- script: echo ${{ parameters.testParam }}
My pipeline yaml that extends the template.
trigger:
- master
extends:
template: my-template.yaml
Then I trigger this pipeline using the queue build REST API: https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.1 with a POST body as below.
{
"parameters": "{\"testParam\": \"hello world\"}",
"definition": {
"id": 50642
},
"sourceBranch": "refs/heads/master"
}
So I'm expecting the pipeline execution will echo hello world instead of N/A. Unfortunately, I'm still seeing N/A in the pipeline results.
Anyone has idea of what happened? Am I miss anything?
I ran into the exact same problem - a pipeline taking runtime parameters that worked when run via the UI, but not via the Queue Build REST API.
I was able to solve this by using an undocumented API, the exact same one that the Az DevOps Pipelines UI calls when running a pipeline:
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=5.1-preview
With the following POST body:
{
"stagesToSkip": [],
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/master"
}
}
},
"templateParameters": {
"testParam": "hello world"
},
"variables": {}
}
Note that with this API, your runtime parameters are being submitted as actual JSON, not stringified JSON, and under the key templateParameters.
As well, don't forget to include the standard headers one might expect for this call:
Content-Type: application/json
Accept: application/json
AUTHORIZATION: bearer $SYSTEM_ACCESSTOKEN.
Using this approach, in the called pipeline, you will always be able to access the value of ${{ parameters.testParam }} whether the pipeline is called via REST API or manually in the UI.
While you're correct that the value is accessible as $(testParam) when executed via REST API, that variable is not populated when running the pipeline in the UI.
As such, I'd recommend using this undocumented API, since the called pipeline can use ${{ parameters.testParam }} without regard to how it's being called. Of course, it's (as of writing) undocumented, so.... ¯_(ツ)_/¯
As well, it should be noted that your pipeline must be formatted as #Josh Gust suggested:
my-template.yaml:
parameters:
- name: testParam
type: string
default: 'N/A'
steps:
- script: echo ${{ parameters.testParam }}
azure-pipelines.yaml:
parameters:
- name: testParam
type: string
default: 'N/A'
trigger:
- master
extends:
template: my-template.yaml
parameters:
testParam: ${{ parameters.testParam }}
Got the solution after spending 2 to 3 Hour:
https://dev.azure.com/{organization}/{project}/_apis/pipelines/2/runs?api-version=6.0-preview.1
Where 2= {pipelineId}
Header :
Authorization: Personal access token. Use any value for the user name and the token as the password.
Type: basic
Content-Type : application/json
Accept : application/json
Right Now I'm using: Postman for testing this API So sharing posting main screenshot:
In the Body part :
{"previewRun":false,"stagesToSkip": [],"resources": {"repositories": {"self": {"refName": "refs/heads/master"}}},"templateParameters": {"testParam": "rawat Rob" },"variables": {}}
previewRun :{If true, don't actually create a new run. Instead, return the final YAML document after parsing templates.}
It is working for me And having test around 5 to 7 time
Seems that it's an issue in Azure DevOps Rest API: https://developercommunity.visualstudio.com/content/problem/1000544/parameters-to-api-rest-build-queue-method.html
I encountered the same problem and noticed that the runtime parameter is introduced to the pipeline run as variable. Thus using $(MyParam) instead of ${{parameters.MyParam}} in the yaml fixes the problem.
Looks like the parameters are not necessary in this case, I merged the yaml into one like below.
# File: azure-pipelines.yml
trigger:
- master
steps:
- script: echo $(testParam)
Note the difference between $(testParam) and ${{ parameters.testParam }}.
Then I trigger it from REST API and it works totally fine.
You're not sending your parameter from your pipeline to the template.
Take a look at how the documentation says this should happen. I haven't tested but I think if you wire the parameter to the template properly, you'll get what you expect using the template.
Basically your template should look like this:
# File: simple-param.yml
parameters:
- name: yesNo # name of the parameter; required
type: boolean # data type of the parameter; required
default: false
steps:
- script: echo ${{ parameters.yesNo }}
And your pipeline should be thus:
# File: azure-pipelines.yml
trigger:
- master
extends:
template: simple-param.yml
parameters:
yesNo: false # set to a non-boolean value to have the build fail
Notice the parameters: yesNo: false
Also, the Runtime Parameters Documentation might suggest that you should define your pipeline parameters as explicit parameters.
The only thing you need to change is the body of the rest api request
It should be as given below
$body='{
"definition": { "id": "50642" },
"sourceBranch": "refs/heads/master",
"templateParameters": {
"testParam": "hello world"
},
"variables": {}
}'
I want to use Azure DevOps Predefine Variable "$(Build.SourcesDirectory)" in My playbook:
Here is my playbook:
---
- hosts: KBR_MTL361
tasks:
- name: copy file
win_copy:
src: D:\Web.config
dest: $(Build.SourcesDirectory)
I am running this ansible-playbook using Azure DevOps Pipeline:
TFS Pipeline Task
But it is not working
Is there anyone who has any idea how to use the variable in the pipeline?
Just add your variables as additional args in the azure-pipelines.yml like this:
- task: Ansible#0
inputs:
ansibleInterface: 'agentMachine'
playbookPathOnAgentMachine: 'ansible/tfs_playbooks/install_agent.yml'
inventoriesAgentMachine: 'file'
inventoryFileOnAgentMachine: 'hosts.yml'
args: '--extra-vars "build_source_dir=$(Build.SourcesDirectory) AGENT_URL=$(AGENT_URL)"'
Then you can access the variables in your playbook:
---
- hosts: localhost
tasks:
- name: show debug
debug:
msg: "Dir {{ build_source_dir }} agent url {{AGENT_URL}}"
if you look here: https://daniel-krzyczkowski.github.io/Parameters-In-Azure-DevOps-Pipelines there is a certain way to pass Pipeline variables to a powershell script, for instance:
[CmdletBinding()]
param (
$ApiManagementServiceName,
$ApiManagementServiceResourceGroup
)
$apimServiceName = $ApiManagementServiceName
$resourceGroupName = $ApiManagementServiceResourceGroup
Write-Host "Api Management Service Name: $($apimServiceName)"
Write-Host "Api Management Resource Group Name: $($resourceGroupName)"
you are using still powershell you say, so give this a try or try to do something similar that works in your case, for me the above approach works pretty well in standard powershell.
I have the following python script with an Azure DevOps pipeline template:
# File: templates/clone-docker-volume.yml
parameters:
sourceVolume: ''
targetVolume: ''
pfaEndpoint: ''
steps:
- task: PythonScript#0
inputs:
scriptSource: 'inline'
script: |
#!/usr/bin/env python3
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
fa = myfunc(target="${{ parameters.pfaEndpoint }}")
When I hard code the ip address calls to the script in the template work as expected, when I change the template such that the ip address is parameterized, I get an error with the following:
HTTPSConnectionPool(host='$(pfaendpoint)', port=443)
I'm invoking the script in the template as follows:
- template: templates/python-template.yml
parameters:
pfaEndpoint: '$(pfaEndpoint)'
I suspect this is the problem that is causing the ip address used in the script to appear as '$(pfaEndpoint)'. Can someone please advise how I resolve this such that the ip address is correctly passed into the template.
you can only use that syntax ${{ parameters.something }} if its a single "thing", you cannot embed it into a string. for that you have to use format operator:
script: |
${{ format('#!/usr/bin/env python3
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
fa = myfunc(target="{0}")', parameters.pfaEndpoint) }}
if you need 2 parameters use this:
${{ format('{0} {1}', parameters.one, parameters.two) }}
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#format
I have web url and i have two options enable/disable , Now I am writing ansible playbook to do this which is in Powershell script
My ansible playbook
---
- hosts: localhost
vars:
applauncher: "xweb"
jobState: "Disable"
serverName: "NETBATCH"
jobName: "Loan1"
tasks:
- name: edit app jobs
uri:
url: 'http://{{ applauncher }}/Edit/{{ jobState }}?Server={{ serverName }}&JobName={{ jobName }}'
method: POST
user: xxxx
password: xxx
I am passing extra vars to disable and enable option , Is it possible to use this option in uri module and which method I should use to select disable/enable option in URL
I think this is what you are after, but it took me a while to figure out what you are asking for. Read about vars_prompt playbook keyword: https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html