jenkins之 pipeline 小尝试

最近,一个小需求,动态建立slave节点来执行自动化用例,原有jenkins 老方式不满足需求,就用到jenkins2的pipeline来实现,但在实现过程中,2个小坑记录下

1、jenkins不能读取file参数中的文件

 在任务有file参数时,如下:

然后在pipeline只引用env.env_conf时,发现找不到上传的文件.....<_>

查看后,原来还是一个bug,见jenkins官网说明,

代替方案:

 使用multi-line string parameter参数,读取后,再写入到文件

 writeFile file: 'demo.ini', text: env.config

 

2、post带node,带脚本

post属于构建后的操作,官网只是这样显示的

Jenkinsfile (Declarative Pipeline)
pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                sh 'echo "Fail!"; exit 1'
            }
        }
    }
    post {
        always {
            echo 'This will always run'
        }
        success {
            echo 'This will run only if successful'
        }
        failure {
            echo 'This will run only if failed'
        }
        unstable {
            echo 'This will run only if the run was marked as unstable'
        }
        changed {
            echo 'This will run only if the state of the Pipeline has changed'
            echo 'For example, if the Pipeline was previously failing but is now successful'
        }
    }
}

NND,这是什么,谁的post会这么简单??

我要在指定节点运行脚本,发邮件。

没办法,又是查阅资料后,原来post可以这么写:

例一:

post {
        success {
            script {
                currentBuild.result = 'SUCCESS'
            }
            step([$class: 'StashNotifier'])
        }
     }

 

例二:带节点生成html,junit

post {
        always {
            node("xxxxx"){
                publishHTML (target: [
            allowMissing: false,
            alwaysLinkToLastBuild: false,
            keepAll: true,
            reportDir: "${env.Version}/AliApiCrul/.",
            reportFiles: 'index.html',
            reportName: "HTML Report"
            ])
                junit "${env.Version}/AliApiCrul/*.xml"
            }

 

posted @ 2018-03-13 15:27  Believer007  阅读(779)  评论(0编辑  收藏  举报