Giter Club home page Giter Club logo

Comments (12)

liuweiGL avatar liuweiGL commented on May 23, 2024

发送失败应该会在jenkins控制台输出错误信息。

看配置应该是参数错误,你换成 TEXT 类型的消息试试:

type: 'TEXT'

from dingtalk-plugin.

liuweiGL avatar liuweiGL commented on May 23, 2024

遇到问题先看日志,再查文档,最后提 issue。

更多的使用案例参考:https://jenkinsci.github.io/dingtalk-plugin/examples/text.html

from dingtalk-plugin.

openstack-test avatar openstack-test commented on May 23, 2024

@liuweiGL 您好,确实没有日志,文档我也看了四次。找不到原因很困惑,希望得到你们的帮助,谢谢

pipeline script 部分配置

    stage ("build") {
        container("golang") {
            sh """
                git config --global url."https://oauth2:[email protected]".insteadOf "https://git.test.com"
                export GOPROXY=https://goproxy.io,direct
                export GOPRIVATE=git.test.com
                export GOPATH=/home/jenkins
                CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main 1111.go
            """
        }
    }
    
    stage('text'){
        post {
            failure {
                dingtalk (
                    robot: '6cc574c3-17fa-4e0c-8724-f7de3376e1b6',
                    type: 'TEXT',
                    text: [
                        'go build失败了,请检查!'
                    ]
                )
            }
        }
    }

jenkins 日志输出

git log -n 1 --pretty=format:%h
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ git config --global url.https://oauth2:[email protected] https://git.test.com
+ export GOPROXY=https://goproxy.io,direct
+ export GOPRIVATE=git.test.com
+ export GOPATH=/home/jenkins
+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main 1111.go
stat 1111.go: no such file or directory
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

from dingtalk-plugin.

liuweiGL avatar liuweiGL commented on May 23, 2024
pipeline {
   agent any

   stages {
      stage('Hello') {
         steps {
                   dingtalk (
                    robot: 'your root id',
                    type: 'TEXT',
                    text: [
                        'go build失败了,请检查!'
                    ]
                )
         }
      }
   }
}

你可以使用这个配置测试一下,我本地是没问题的:
image

from dingtalk-plugin.

openstack-test avatar openstack-test commented on May 23, 2024

@liuweiGL 这种是声明式pipeline方式。我是用的pipeline script。请问与使用pipeline的方式有没关系呢,谢谢

from dingtalk-plugin.

liuweiGL avatar liuweiGL commented on May 23, 2024

这两种方式调用没有区别。

应该是你的 pipeline 写错了,stage ("build") 节点报错,不会触发 stage ("text") 节点的 failure 事件。

from dingtalk-plugin.

openstack-test avatar openstack-test commented on May 23, 2024

@liuweiGL 我尝试过这样写,也不行

  stage ("build") {
        container("golang") {
            sh """
                git config --global url."https://oauth2:[email protected]".insteadOf "https://git.test.com"
                export GOPROXY=https://goproxy.io,direct
                export GOPRIVATE=git.test.com
                export GOPATH=/home/jenkins
                CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main 1111.go
            """
        }

        post {
            failure {
                dingtalk (
                    robot: '6cc574c3-17fa-4e0c-8724-f7de3376e1b6',
                    type: 'TEXT',
                    text: [
                        'go build失败了,请检查!'
                    ]
                )
            }
        }
    }

也尝试过把 stage('text'){}放在pipeline 最后。 实在无解了,特此劳烦请教作者您,谢谢。网上查阅到的资料均说pipeline script方式不支持钉钉插件,需要用声明式pipeline。

from dingtalk-plugin.

liuweiGL avatar liuweiGL commented on May 23, 2024

你在 failure 里面输出一个 echo,看看是否执行到了。

from dingtalk-plugin.

openstack-test avatar openstack-test commented on May 23, 2024

没有输出,不知道为什么没有执行到,估计只能改用声明式pipeline或者通过脚本调用钉钉发送通知了。

stage ("build") {
            container("golang") {
                sh """
                    git config --global url."https://oauth2:[email protected]".insteadOf "https://git.test.com"
                    export GOPROXY=https://goproxy.io,direct
                    export GOPRIVATE=git.test.com
                    export GOPATH=/home/jenkins
                    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main 1111.go
                """
            }
            
            post {
                failure {
                    echo "aaaaaaaaaaaaaaaaaaa"
                    dingtalk (
                        robot: '6cc574c3-17fa-4e0c-8724-f7de3376e1b6',
                        type: 'TEXT',
                        text: [
                            'go build失败了,请检查!'
                        ]
                    )
                }
            }
        }
        
        stage('text'){
            post {
                failure {
                    echo "aaaaaaaaaaaaaaaaaaa"
                    dingtalk (
                        robot: '6cc574c3-17fa-4e0c-8724-f7de3376e1b6',
                        type: 'TEXT',
                        text: [
                            'go build失败了,请检查!'
                        ]
                    )
                }
            }
        }
+ git config --global url.https://oauth2:[email protected] https://git.test.com
+ export GOPROXY=https://goproxy.io,direct
+ export GOPRIVATE=git.test.com
+ export GOPATH=/home/jenkins
+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main 1111.go
stat 1111.go: no such file or directory
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

from dingtalk-plugin.

liuweiGL avatar liuweiGL commented on May 23, 2024

我真是搞不明白,你到现在都还纠结什么申明式 pipeline干嘛?

你的 failure 事件都没执行,跟插件有什么关系呢?

很明显就是你的 container 节点异常,导致整个 pipeline 终止执行,直接退出了。

from dingtalk-plugin.

openstack-test avatar openstack-test commented on May 23, 2024

@liuweiGL 我们代码编译是在container 容器中做的,jenkins master和slave基于k8s pod跑的。有什么解决办法吗? 需求是针对每个pipeline步骤做失败检测,即失败了则发送钉钉通知告知相关信息。

from dingtalk-plugin.

oldthreefeng avatar oldthreefeng commented on May 23, 2024

@openstack-test

    stage('DingDing') {
        script {
            def msg = "构建失败,请及时查看原因"
            def imageUrl = "https://www.iconsdb.com/icons/preview/red/x-mark-3-xxl.png"
            def dingdingtoken = "https://oapi.dingtalk.com/robot/send?access_token=****************************"
            if (currentBuild.currentResult=="SUCCESS"){
                imageUrl= "http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png"
                msg ="发布成功"
            }
            sh "sh ${JENKINS_HOME}/dingding.sh ${BUILD_TAG} ${BUILD_URL} ${msg} ${imageUrl} ${dingdingtoken}"
        }
    }

dingding.sh

#!/bin/sh
title=$1
messageUrl=$2
picUrl=$4
text=$3
PHONE="158215*****"
TOKEN=$5
DING="curl -H \"Content-Type: application/json\" -X POST --data '{\"msgtype\": \"link\", \"link\": {\"messageUrl\": \"${messageUrl}\", \"title\": \"${title}\", \"picUrl\": \"${picUrl}\", \"text\": \"${text}\",}, \"at\": {\"atMobiles\": [${PHONE}], \"isAtAll\": false}}' ${TOKEN}"
eval $DING

我是这么的 ...

from dingtalk-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.