VS Code Jenkinsfile docker.withRegistry {...} brackets do not match error - docker

I'm writing a jenkinsfile in VS Code and when I use docker.withRegistry("some.registry"){...} I get a brackets do not match error inside of code. It parses fine inside jenkins, but this error inside of code is bugging me a lot. As soon as anything goes between the {} I get the error show up on the closing bracket.
Even copying in directly from the documentation from the Jenkins website gives the same issue.
Any ideas?

Oddly enough I had the same issue when I was using a private registry with a credentials ID, when I switched away from single quotes to double quotes the error went away, you could give that a try?
docker.withRegistry("https://some.registry", "docker-registry-creds") {
def customImage = docker.build("my-image:${env.GIT_COMMIT}")
}

As mentioned by Carl here, this happens when you have the following 2 characters, in this particular order, in a single quoted string:
'/*'
So strings like the following will trigger the error:
'**/*.xml'
'/some/path/to/random/files/*.py'
Just use double quote in those strings, and all the errors will go away:
"**/*.xml"
"/some/path/to/random/files/*.py"

I noticed this also occurs when using a parenthesis in single quotes. Again fixed by putting these in double quotes.
e.g.:
def something= somethingelse.tokenize('(')
can be replaced by
def something= somethingelse.tokenize("(")

Related

How to maintain the escaped quotes in an expression in Spring Cloud Data Flow?

When I configure my stream to be depoyed, in which I'm using a processor (transform, script or http-request), in the "expression" atribute I need to set an expression that contains quotes and double quotes (escaped). The expression works properly the first time I set and allows to deploy the stream, but if I undeploy the stream and try again to deploy it, the spring cloud data flow throws state machine exception because the backslashes used to escape the double quotes are removed.
I already follow the considerations in the Spaces and Quotes documentation, but I think that it only applies to the streams definition and not to the deployment time.
The URL of the spaces and quotes documentarion is: https://docs.spring.io/spring-cloud-dataflow/docs/current-SNAPSHOT/reference/htmlsingle/#shell-white-space
And the sample of the type of expression required:
expression="new String('{\"size\": 1,\"sort\": {\"timestamp\": \"desc\"},\"query\": {\"prefix\": {\"integrationname\": \"63320e0d313862934667225f\"}}}')"
The stream could be as simple as:
http | transform | log
The firs time the expression is set looks like as follows:
expression="new String('{\"size\": 1,\"sort\": {\"timestamp\": \"desc\"},\"query\": {\"prefix\": {\"integrationname\": \"63320e0d313862934667225f\"}}}')"
Deploying correctly the stream.
Once the stream is undeployed and try to deploy it again, the espression looks like:
expression="new String('{"size": 1,"sort\": {"timestamp": "desc"},"query": {"prefix": {"integrationname": "63320e0d313862934667225f"}}}')"
Where the backslashes were removed, causing the state machine exception because of the unescaped double quotes.
Thanks in advance
We are looking at Issue #5145 and will update the issue when we have fixed it.
In the meantime I would suggest using the spring-cloud-dataflow-shell or the REST API to automate deployments where you provide the properties every time as needed.

code blocks don't work in Spyder (Anaconda3)

I am a beginner in Python using Spyder to code from Anaconda3.
I tried to enter such codes in Spyder (Python 3.7). I pressed "Enter" when trying to split the codes and the indents appear auto. But it always returns with "SyntaxError: invalid syntax" and "SyntaxError: 'return' outside function".
E.g. 1
data = {'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],
'year':[2000,2001,2002,2001,2002,2003],
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]}
When I press F9 in either line, it returns "SyntaxError: invalid syntax".
E.g. 2
def f(x):
return pd.Series([x.min(),x.max()],index=['min','max'])
Press F9 to run the line, it returns "SyntaxError: unexpected EOF while parsing". If in the second line, it returns "SyntaxError: 'return' outside function".
In addition, I also tried to put "\"s at the end of each line. It doesn't work either. And find from webpages that if the lines end with : or , then you don't need \ to split.
But!!! if I deleted the 'Enters' and put everything in a single line without splits, it works well totally.
Why my python cannot work with code blocks? How can I fix it with Anaconda3?
Thank you so much~~~~
The problem is that you need to select the entire function before pressing F9, if you select only a part of it it will raise an error
You can use \ at the end of each line to tell Python that the line continues below:
data = {\
'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],\
'year':[2000,2001,2002,2001,2002,2003],\
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]\
}
Having the dictionary split across multiple lines may look pretty, but it is not proper syntax. I've also been tripped up by tutorials that show their dictionaries like that :|
This may not work in interpreters other than IDLE.

Jenkins file can we use the IF statement

in Jenkins file one of the variable is having the comma separated values like below.
infra_services=[abc,def,xyz]
when I write the below code it was throwing an error.
if ("{$Infra_Services}".contains("xyz"))
then
echo "$Infra_Services"
fi
yes you can do if statements in a Jenkinsfile. However if you are using declarative pipeline you need to brace it with the step script.
Your issue comes from the fact you did not put any double quotes around "abc" and all the elements of your array
infra_services=[abc,def,xyz]
​
A second error will raise after you fix this. If infra_services is an array, to manipulate it you should not try to cast it as string. It should throw when you do "{$Infra_Services}"
here is a working example
​def Infra_Services = ["abc","def","xyz"]
if (Infra_Services.contains("xyz")) {
println "found"
}​​
My advice is to test your groovy before running it on jenkins, you will gain precious time. Here is a good online groovy console I use to test my code. running the groovy console from terminal is an alternative
https://groovyconsole.appspot.com/

Enclosing a python Path variable in quotes?

I need help fixing a Python script, but know ABSOLUTELY NOTHING about Python (though I am an experienced programmer so I get the jargon.)
I have this script that is trying to write output to a generated path, but when I run it, it gives me an error saying something about "E:\Program", and when I check, sure enough, it creates a folder named "Program" in the root of my E: drive. I'm CERTAIN it is trying to write to "E:\Program Files" but the space is terminating the command.
I did find where "path" is assigned:
path = tkm.path_archuncomp + bs.path + bs.name + '.ext'
How would I enclose that path in quotes that are assigned to the variable?
Inserting the quotes character appears to be the same as languages like C. Simply use "slash" notion:
path = \" + some_variable + \"
Unfortunately for me, repairing the script is more complicated than that, and doing so only created errors, so I can't confirm that was done properly. :(

TinyGet with URL Parameters

Anyone still using TinyGet?
When I pass a single query string parameter, everything works fine. As soon as I try to add a second param I get an error.
Here's an example of the error I'm getting:
C:\Program Files\IIS Resources\TinyGet>tinyget -srv:mydomain.com -uri:/Search/Results?q=food&pIndex=5 -loop:10
'pIndex' is not recognized as an internal or external command, operable program or batch file.
I've reviewed resources like http://code.google.com/p/toolsdotnet/wiki/TinyGet and I can't get this to work. Any ideas?
(PS: I tried tagging this "TinyGet" but I don't have enough rep, in case someone else wants to do that.)
I got an answer over at the IIS forums (http://forums.iis.net/p/1166670/1940071.aspx#1940071).
The ampersand must be escaped with the ^ character, so in this case the call would be:
C:\Program Files\IIS Resources\TinyGet>tinyget -srv:mydomain.com -uri:/Search/Results?q=food^&pIndex=5 -loop:10
You could also just wrap the uri in quotes.

Resources