If I run a post request like this, it works:
def myFunction():
contentTypeHeader = {
'Content-type': 'application/json',
}
data = """
{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "master",
"selector": {
"type": "custom",
"pattern" : "mypipeline"
}
},
"variables": []
}
"""
http = urllib3.PoolManager()
headers = urllib3.make_headers(basic_auth='{}:{}'.format("username", "password"))
headers = dict(list(contentTypeHeader .items()) + list(headers.items()))
try:
resp = http.urlopen('POST', 'https://api.bitbucket.org/2.0/repositories/owner/slugg/pipelines/', headers=headers, body=data)
print('Response', str(resp.data))
except Exception as e:
print('Error', e)
myFunction()
However, if instead of hardcoding the values, I try to pass them on as a function:
def myFunction(bitbucket_branch, pipeline_name):
contentTypeHeader = {
'Content-type': 'application/json',
}
data = """
{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "${bitbucket_branch}",
"selector": {
"type": "custom",
"pattern" : "${pipeline_name}"
}
},
"variables": []
}
"""
...
myFunction("master","mypipeline")
I get this error:
Response b'{"error": {"message": "Not found", "detail": "Could not find last reference for branch ${bitbucket_branch}", "data": {"key": "result-service.pipeline.reference-not-found", "arguments": {"uuid": "${bitbucket_branch}"}}}}'
Additionally, in my function :
def myFunction(bitbucket_branch, pipeline_name):
the parameters are still in a light color in my VSCode, which indicates that the parameters aren't actually being used in the function.
Perhaps I am doing something wrong with encoding strings but can't figure out what exactly.