groovy

Jenkins Read a Specific Line of a File in Jenkinsfile with Groovy

我的梦境 提交于 2021-02-18 18:04:28
问题 I am trying to read a specific line of an html file in a Jenkins stage with Groovy and save its contents to an environment variable. The problem is, File and readLines() are not allowed. I am able to load a file with env.WORKSPACE = pwd() def file = readFile "${env.WORKSPACE}/file.html" Provided in this answer But how can I access instantly to the contents of line n ? I am using Jenkins 2.32 回答1: Just going to leave documented here, but you can also use readLines(). def file = readFile

does not have a matching glue code in Groovy-cucumber

人走茶凉 提交于 2021-02-17 05:52:50
问题 I'm using cucumber-groovy with maven based framework and unable to find the glue to stepDefinitions. Getting does not have a matching glue code in feature file. It is in Cucumber-maven Project. I have converted the Feature folder to 'Source folder'. Error : Unable to create src/test/groovy & src/test/resource (to use as feature's folder) Here is my Test Runner CucumberOptions: @CucumberOptions( features = ["src/test/resources/"], glue = ["com.esw.taa.avs.steps"], plugin = ["html:esw-tests

How can I male groovy on Jenkins mask the output of a variable the same way it does for credentials?

无人久伴 提交于 2021-02-17 03:59:05
问题 Is there a way in groovy on Jenkins to take an arbitrary String variable - say the result of an API call to another service - and make Jenkins mask it in console output as it does automatically for values read in from the Credentials Manager? 回答1: UPDATED SOLUTION: To hide the output of a variable you can use the Mask Password Plugin Here is an exemple: String myPassword = 'toto' node { println "my password is displayed: ${myPassword}" wrap([$class: 'MaskPasswordsBuildWrapper',

Gradle 的下载安装配置以及创建第一个Gradle 项目

老子叫甜甜 提交于 2021-02-15 20:25:54
1. 什么是Gradle? Gradle是一个开源的构建自动化工具,专注于灵活性和性能。 Gradle构建脚本使用Groovy或Kotlin DSL编写。 阅读Gradle功能,了解Gradle的功能。 高度可定制 - Gradle以一种可以以最基本的方式定制和扩展的方式建模。 快速 - Gradle通过重用先前执行的输出,仅处理已更改的输入以及并行执行任务来快速完成任务。 功能强大 - Gradle是Android的官方构建工具,并支持许多流行的语言和技术。 2. Gradle 的下载和安装 我们可以安装Gradle 构建工具在Linux,MacOS ,windows 操作系统上,这个文档覆盖了使用包管理器像SDKMAN!,Homebrew,或者Scoop的安装方法。 使用Gradle Wrapper是升级Gradle的推荐方法 我们可以找到所有的发布版本在 发布页面 1.1 Gradle 必要条件 Gradle 可以运行在大多数的操作系统中,但是需要JDK 或者JRE 8 以上版本 检查方法,打开操作系统命令行终端,输入命令 java -version 执行成功如下所示: 注意: Gradle附带了自己的Groovy库,因此不需要安装Groovy。 Gradle会忽略任何现有的Groovy安装。 Gradle 会在path环境变量中招JDK 安装路径,我们可以设置JAVA

How to create Jenkins jobs automatically in using JobDSL plugin

隐身守侯 提交于 2021-02-11 17:10:19
问题 I was trying to configure JobDSL plugin in Jenkins to automatically create Jenkins jobs for all repos in my Github account, and tried the following code snippet but it doesn't show any repos using Github API URL, so I found the issue was in authentication. Now I've configured the Github credentials in the Jenkins global configurations. My question is how can I add this credentials in the code snippet to authenticate. def organization = 'mygitorg' repoApi = new URL("https://api.github.com/orgs

How to create Jenkins jobs automatically in using JobDSL plugin

橙三吉。 提交于 2021-02-11 17:05:37
问题 I was trying to configure JobDSL plugin in Jenkins to automatically create Jenkins jobs for all repos in my Github account, and tried the following code snippet but it doesn't show any repos using Github API URL, so I found the issue was in authentication. Now I've configured the Github credentials in the Jenkins global configurations. My question is how can I add this credentials in the code snippet to authenticate. def organization = 'mygitorg' repoApi = new URL("https://api.github.com/orgs

Spock - Mock private field

只愿长相守 提交于 2021-02-11 15:06:41
问题 I have to mock private field: public class A{ private final B b; public A(){ this.b = new B(new OtherService) } public test(){ int i = b.test() if(i == 0) b.test1() else b.test2() } } and I have to create unit tests for methods in this kind of class and I have to mock class B is it even possible here? 回答1: Please read my remarks here and here or in many other questions of this kind I answered concerning dependency injection (DI). The lack thereof in your tightly coupled application design is

Escaping parameters with white space in the docker .withRun command in Jenkins declarative pipeline

倖福魔咒の 提交于 2021-02-11 14:33:09
问题 Currently unable to get my head around how to correctly pass my parameters from Jenkins, to the docker .withRun function, in Jenkins Docker Plugin (specifically in declarative pipelines), which contain whitespace. Tried an unknown amount of methods to get this working and currently at a loss. See code below stage('Send Notifications') { steps { // Send a notification based on the parameters passed script { docker.withRegistry(registry, registryCredentials) { // echo "${TITLE}" docker.image(

SOAP UI - Return two different responses for two different POST Request Payloads for same REST API end point

柔情痞子 提交于 2021-02-11 14:12:35
问题 I have a REST POST API end point - "abc/def". It's request payload has (out of many other fields) a field "yourId" which can take either 1 or 2 as shown below: { "yourId":"1" } OR { "yourId":"2 } On the basis of the value of "yourId", I need to return two different responses either 1. YOUR_RESPONSE_1 OR 2. YOUR_RESPONSE_2 for which I have written a groovy script as shown below: def requestBody = mockRequest.getRequestContent() log.info "Request body: " + requestBody yourId="yourId" id1="1"

SOAP UI - Return two different responses for two different POST Request Payloads for same REST API end point

扶醉桌前 提交于 2021-02-11 14:09:36
问题 I have a REST POST API end point - "abc/def". It's request payload has (out of many other fields) a field "yourId" which can take either 1 or 2 as shown below: { "yourId":"1" } OR { "yourId":"2 } On the basis of the value of "yourId", I need to return two different responses either 1. YOUR_RESPONSE_1 OR 2. YOUR_RESPONSE_2 for which I have written a groovy script as shown below: def requestBody = mockRequest.getRequestContent() log.info "Request body: " + requestBody yourId="yourId" id1="1"