skip to Main Content

I am trying to pass the string to git page through api call from Pipeline run but getting some string formatting error

gitCheckInputString = '''{"name":"''' + gitCheckName + '''","output":{"title":"''' + gitCheckName + '''","summary":"''' + message + '''","text":"''' + "The summary:n{ unaudited: " + str($(params.unaudited)) + "n    live: " + str($(params.live)) + "n    real: " + str($(params.real)) + "  }" + "n " + [Click on the link to see results on the Tekton build pipeline](''' + pipelineURL + ''') + '''"}}'''

print(gitCheckInputString)
SyntaxError: invalid syntax. Perhaps you forgot a comma?

The expected output is :

Click on the link to see results on the Tekton build

The summary: 

{ unaudited: 10
  
  live: 0
  
  real: 9
}

2

Answers


  1. ”’ " is invalid you can’t put 2 string next to each other like that.

    Maybe have a coma or a +. I am not sure because I don’t really understand what you are trying to do. Make your code a bit more readable and I am sure you will understand the issue yourself. It’s not a great practice to have big lines like these one. Try splitting it.

    The error is here: gitCheckName + '''","output"

    Login or Signup to reply.
  2. Good morning friend, looking at your code is complicated, there are a lot of items inside a string, a lot (" "), (‘ ‘), (""" ""), this reference you are trying I don’t understand. But looking at first time, it looks like you’re trying to pass a dictionary or a json. I’m not sure if that would be it. But like the example you posted as an output, it looks like you’re trying to make a request, I’m not sure.

    Well, I fixed it, an example dict:

    
    gitString = {
        'name': 'gitCheckName',
        'output': {
            'title' : 'gitCheckName',
            'summary': 'message',
            'text': '',
            'The Summary': {
                'unaudited': '$(params.unaudited)',
                'live': '$(params.live)',            
            },
            'pielineURL': '',
        }
        
    }
    
    print(gitString)
    
    

    result:

    {'name': 'gitCheckName', 'output': {'title': 'gitCheckName', 'summary': 'message', 'text': '', 'The Summary': {'unaudited': '$(params.unaudited)', 'live': '$(params.live)'}, 'pielineURL': ''}}
    
    

    But as you said, you are trying to make a call, if so you will have to build a url, taking advantage of the previous dict with the parameters.

    Using simple examples:

    component_1 = gitString['name']
    component_2 = gitString['output']['title']
    
    url = f'https://yourlink.com/{component_1}/{component_2}'
    url
    
    

    result:

    ‘https://yourlink.com/gitCheckName/gitCheckName’

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search