小编mke*_*erz的帖子

如何修复管道脚本“预期一步”错误

我正在尝试在 Jenkins 中运行一个简单的管道脚本,分为 2 个阶段。脚本本身会创建一个 textFile 并检查它是否存在。但是,当我尝试运行该作业时,出现“预期的步骤”错误。

我在某处读到过,你不能有一个if内部步骤,所以这可能是问题所在,但如果是这样,我如何在不使用的情况下进行检查if

pipeline {
    agent {label 'Test'}
    stages {
        stage('Write') {
            steps {
                writeFile file: 'NewFile.txt', text: 
                '''Sample HEADLINE'''
                println "New File created..."
            }
        }
        stage('Check') {
            steps {        
                Boolean bool = fileExists 'NewFile.txt'
                if(bool) {
                    println "The File exists :)"
                }
                else {
                    println "The File does not exist :("
                }            
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望脚本在代理工作区中创建一个“NewFile.txt”并将文本打印到控制台以确认它存在。

但我实际上得到了两个“预期的一步”错误。在以Boolean bool = ... 和开始的线路上if(bool) ...

groovy jenkins jenkins-pipeline

26
推荐指数
1
解决办法
3万
查看次数

如何在 Jenkinsfile 中签出存储库之前清理管道

我想进行Jenkins git 插件文档clean before checkout中描述的操作:

签出前清理 在每次签出之前通过删除所有未跟踪的文件和目录(包括 .gitignore 中指定的文件和目录)来清理工作区。...

但是如何将此选项添加到作为第一步执行的默认结账步骤中?

我觉得它应该是 git 插件扩展的一个选项,可以包含到optionsJenkinsfile 块中,如文档中所述:

options 指令允许从 Pipeline 本身配置特定于 Pipeline 的选项。Pipeline 提供了许多这样的选项,例如 buildDiscarder,但它们也可能由 插件提供......

但是如何知道这个插件提供了哪些选项及其名称呢?在文档中没有找到它,我也可能是错误的,clean before checkout应该放在optionsJenkinsfile 块中。

请帮忙。

jenkins jenkins-plugins jenkins-pipeline jenkins-declarative-pipeline jenkins-git-plugin

10
推荐指数
1
解决办法
2万
查看次数

如何使用 jenkins pipline 步骤在 docker 镜像中安装 pip ?

我有这个Dockerfile

FROM python:3.7

CMD ["/bin/bash"]
Run Code Online (Sandbox Code Playgroud)

和这个Jenkinsfile

pipeline {
agent {
    dockerfile {
        filename 'Dockerfile'
    }
}
stages {
    stage('Install') {
        steps {
            sh 'pip install --upgrade pip'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这会导致以下错误:

The directory '/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/.cache/pip' or its …
Run Code Online (Sandbox Code Playgroud)

jenkins docker jenkins-pipeline

8
推荐指数
1
解决办法
3887
查看次数

Jenkins Pipeline阶段跳过基于管道中定义的groovy变量

我试图跳过stage基于常规变量,该变量值将在另一个阶段计算。

在下面的示例中,Validate阶段是基于环境变量有条件地跳过的VALIDATION_REQUIRED,我将在构建/触发作业时传递该环境变量。---这按预期工作。

Build而即使isValidationSuccess变量设置为 ,阶段也始终运行false。我尝试更改when条件表达式,例如{ return "${isValidationSuccess}" == true ; } or{ return "${isValidationSuccess}" == 'true' ; }但没有成功。打印变量时它显示为“false”

def isValidationSuccess = true 
 pipeline {
    agent any
    stages(checkout) {
        // GIT checkout here
    }
    stage("Validate") {
        when {
            environment name: 'VALIDATION_REQUIRED', value: 'true'
        }
        steps {
            if(some_condition){
                isValidationSuccess = false;
            }
        }
    }
    stage("Build") {
        when {
            expression { return "${isValidationSuccess}"; }
        }
        steps { …
Run Code Online (Sandbox Code Playgroud)

groovy continuous-deployment jenkins jenkins-groovy jenkins-pipeline

7
推荐指数
1
解决办法
9568
查看次数

Java 15 的密封类特性中的最终类和非密封类有什么区别?

我有以下密封接口(Java 15):

public sealed interface Animal permits Cat, Duck {

    String makeSound();
}
Run Code Online (Sandbox Code Playgroud)

该接口由 2 个类实现:

public final class Cat implements Animal {

    @Override
    public String makeSound() {
        return "miau";
    }
}

public non-sealed class Duck implements Animal {

    @Override
    public String makeSound() {
        return "quack";
    }
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我之间的差异finalnon-sealedfinal阻止我创建其他子类,但什么行为non-sealed适用于Duck

java sealed-class java-15 java-sealed-type

7
推荐指数
1
解决办法
607
查看次数

Jenkinsfile:如何使用命名参数调用 groovy 函数

我有一个简单的声明式管道,里面有函数。如何正确使用函数的命名参数?

def getInputParams(param1='a', param2='b') {
    echo "param1 is ${param1}, param2 is ${param2}"
}

pipeline {
...
...
    stages {
        stage('Test) {
            steps {
                getInputParams(param1='x', param2='y')
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么命名参数在函数中变为空?

[Pipeline] echo
param1 is null, param2 is null
...
Run Code Online (Sandbox Code Playgroud)

好吧,我可以调用类似的函数getInputParams('x', 'y'),但它不是人类可读的(参数数量将来可能会增加)

groovy jenkins jenkins-pipeline

6
推荐指数
1
解决办法
5462
查看次数

找不到这样的字段:运行我的 jenkinsfile 时字段 java.lang.String sinput 错误

获取No such field found: field java.lang.String sinput错误而运行我的Jenkinsfile。

我开发了一个 Jenkinsfile,它可以接受用户输入,并进一步在远程机器上运行一个命令,将用户输入作为变量

stages {
    stage("Interactive_Input") {
        steps {
            script {
                def apiinput
                def userInput = input(
                        id: 'userInput', message: 'This is my project',
                        parameters: [
                                string(defaultValue: 'None',
                                        description: 'Enter the name of the service',
                                        name: 'sinput'),
                                
                        ])
                // Save to variables. Default to empty string if not found.
                apiinput = userInput.sinput?:''
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

groovy jenkins jenkins-pipeline jenkins-declarative-pipeline

4
推荐指数
2
解决办法
7739
查看次数

如何从独立于 Vaadin 视图的 JS 调用后端方法?

我有以下场景。Javascript 在前端执行并对事件做出反应。如果捕获到事件,则调用特定的后端方法。

我像下面这样初始化后端。该方法在我的Vaadin 14视图之一的初始化期间被调用。

window.init = function(element) {
    window.element = element;
    ...
}
Run Code Online (Sandbox Code Playgroud)

看法:

public class TestView extends Div {
   public TestView() {
      ...
      UI.getCurrent().getPage().executeJs("init($0)", this);
   }
}
Run Code Online (Sandbox Code Playgroud)

稍后在window.element.$server.onTestEvent();前端调用方法。

被调用的后端方法:

@ClientCallable
private void onTestEvent() {
    System.out.println("Test");
}
Run Code Online (Sandbox Code Playgroud)

现在的问题:

我将视图传递为element.

如果我更改视图,element我传递的视图将被销毁,因此即使在前端捕获事件(在后端侧)也无法执行。

Vaadin 14是否提供了一种在所有视图中“全局”存储对象的方法?我希望应用程序独立于我当前访问的视图对事件做出反应。

javascript java vaadin vaadin14

1
推荐指数
1
解决办法
124
查看次数

如何在Vaadin 14中播放声音?

我想在使用开发的其中一个应用中播放声音(.wav,作为byte [])Vaadin 14。不幸的是,我没有找到该用例的组件。

提供了Vaadin 8 Audiohttps://vaadin.com/api/framework/8.5.2/com/vaadin/ui/Audio.html),但Vaadin 14中不提供。

我认为有一种解决方案,只需使用HTML <audio>并导入它即可。

<body>
  <audio src="test.wav" controls autoplay loop>
    </audio>
</body>
Run Code Online (Sandbox Code Playgroud)

是否还有“ Vaadin 14”解决方案?

java vaadin html5-audio vaadin14

0
推荐指数
2
解决办法
176
查看次数