groovy

How to convert String to int in Groovy the right way

独自空忆成欢 提交于 2021-02-06 10:12:18
问题 First of all, I am aware of question 'Groovy String to int' and it's responses. I am a newbe to Groovy language and right now playing around some basics. The most straightforward ways to convert String to int seem to be: int value = "99".toInteger() or: int value = Integer.parseInt("99") These both work, but comments to these answers got me confused. The first method String.toInteger() is deprecated, as stated in groovy documentation. I also assume that Integer.parseInt() makes use of the

How to convert String to int in Groovy the right way

不想你离开。 提交于 2021-02-06 10:10:42
问题 First of all, I am aware of question 'Groovy String to int' and it's responses. I am a newbe to Groovy language and right now playing around some basics. The most straightforward ways to convert String to int seem to be: int value = "99".toInteger() or: int value = Integer.parseInt("99") These both work, but comments to these answers got me confused. The first method String.toInteger() is deprecated, as stated in groovy documentation. I also assume that Integer.parseInt() makes use of the

How to copy Jenkins secret files

限于喜欢 提交于 2021-02-06 09:44:31
问题 I have already added 2 secret files to Jenkins credentials with names PRIVATE-KEY and PUBLIC-KEY . How can I copy those 2 files to /src/resources directory inside a job? I have the following snippet withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'my-private-key'), file(credentialsId: 'PUBLIC_KEY', variable: 'my-public-key')]) { //how to copy, where are those files to copy from? } 回答1: Ok, I think I managed to do it. my-private-key variable is a path to the secret, so I had to

Groovy def l = [1, 2, 3] as BlockingQueue

萝らか妹 提交于 2021-02-05 12:02:04
问题 If I write something like def l = [1, 2, 3] as Socket which is obviously nonsense, I get this: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[1, 2, 3]' with class 'java.util.ArrayList' to class 'java.net.Socket' That makes sense. Now I try something less adventurous: import java.util.concurrent.BlockingQueue def l = [1, 2, 3] as BlockingQueue println l.class println l This doesn't throw an exception, and prints the following: class ArrayList1_groovyProxy [1

Groovy def l = [1, 2, 3] as BlockingQueue

天大地大妈咪最大 提交于 2021-02-05 12:01:06
问题 If I write something like def l = [1, 2, 3] as Socket which is obviously nonsense, I get this: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[1, 2, 3]' with class 'java.util.ArrayList' to class 'java.net.Socket' That makes sense. Now I try something less adventurous: import java.util.concurrent.BlockingQueue def l = [1, 2, 3] as BlockingQueue println l.class println l This doesn't throw an exception, and prints the following: class ArrayList1_groovyProxy [1

Docker - executable file not found in $PATH

元气小坏坏 提交于 2021-02-05 07:56:07
问题 In my Ubuntu Server I have following directory structure: /home/docker/groovy . In this location I have simple groovy file. On Docker it is running container groovy_repo_1 . After I entered groovy directory I wanted to perform such script on container: docker exec groovy_repo_1 docker.groovy Output: rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"docker.groovy\": executable file not found in $PATH" Why is it happen?

Date Time Conversion based on the TimeZone Java/Groovy

吃可爱长大的小学妹 提交于 2021-02-05 06:40:27
问题 I am in MST and I want my Date in PST. I set the timeZone that I want. Now if i do c.getTime() I always get my server time. Instead I want Pacific Date time. Please help How to get the date time Object in the specified timezone. Calendar c= Calendar.getInstance(); TimeZone timezone= TimeZone.getTimeZone("PST"); c.setTimeZone(timezone) 回答1: Or, use JodaTime @Grab( 'joda-time:joda-time:2.3' ) import org.joda.time.* def now = new DateTime() println now.withZone( DateTimeZone.forTimeZone(

JSR223 (Groovy) cannot access MongoDB(3.0.3) in Jmeter(2.13)

萝らか妹 提交于 2021-02-04 20:52:28
问题 I have a problem in my JSR 223 Groovy script when it tries to access MonDB 3.0.3 with authentication enabled from JMeter 2.3 : import com.mongodb.DB; import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder; DB db = MongoDBHolder.getDBFromSource("mongoDS", "${mongodb_database}", "${mongodb_user}", "${mongodb_password}"); DBCollection coll = db.getCollection("users"); BasicDBObject query = new BasicDBObject("userId",vars.get("userId")); DBCollection coll = db.getCollection("users"); This

重磅:Python/Java/C 2020年之争!谁是你心中的NO.1?

六月ゝ 毕业季﹏ 提交于 2021-02-04 19:11:17
Python赢得了TIOBE年度编程语言奖!这是历史上第四次获得,并创下纪录!这个奖项被授予在一年中最受欢迎的编程语言。Python流行度在2020年实现了2.01%的正增长。编程语言C ++紧随其后,增长了1.99%。其他获奖者是C(+1.66%),Groovy(+ 1.23%)和R(+ 1.10%)。 Python 近两年一直霸占编程语言排行榜 TOP10,受欢迎程度有目共睹。其实在企业招聘层面也可以从侧面看出,大中小企业甚至国营企业已经陆续开始使用 Python 开发。 那 Python 的市场需要怎么样呢?先来看张图: △ 图片来源职友集1月25日数据 Django、Pandas、Linux都是 Python 最基础的内容,可见大厂招聘 Python 开发也离不开基本功,基础是否扎实也决定了个人的薪资情况。 基于此小编整理了一些Python学习路线,我把它再次推荐给你! 今天免费就能获得全部资料!并且在学习的过程中,还可以参与我们的直播学习! 这份【 学习内容 】,仅供大家交流学习使用,捣乱和发广告的勿加。 扫码添加CSDN老师 免费领取学习资料+课程规划 作为程序员技术社区,一直秉承着“成就一亿技术人”的使命,为帮助 Python 小白从 0 开始系统实战各个应用方向,打好 Python 各个应用岗位的核心能力!CSDN 发起了【Python 全栈开发工程师】

How to add timestamp for artifacts in Jenkins

这一生的挚爱 提交于 2021-02-04 16:40:50
问题 I have following Jenkisfile and I'm trying to upload the artifacts with a timestamp. import groovy.transform.Field @Field def timeStamp = Calendar.getInstance().getTime().format('YYYYMMdd-hhmmss',TimeZone.getTimeZone('CST')) node { stage('Creating some artifacts') { sh 'touch hello.txt hi.txt' } stage('Uploading artifacts') { def server = Artifactory.server ('art-1') def uploadSpec = """{ "files": [ { "pattern": "*.txt", "target": "repo1/Dev/${env.BUILD_NUMBER}/*.txt.${timeStamp}" } ] }"""