jenkins api也提供了类似于SDK,有py,go,java的。基于Jenkins去开发,使用SDK就行了。一般不会通过这种API方式去访问,用SDK更加安全一些。SDK别人帮你写好了,对于项目集成更加方便。
WEB API写一些脚本的时候可能会用到。
也可以对Jenkins进行插件的开发,这些也可以基于共享库或者函数来实现,只不过在界面上通过添加参数来实现。这样也能够实现类似插件的功能。
你想看某个作业的信息,后面加上api就行了。
项目API
可以将这些api封装到共享库里面去
获取项目信息
curl --location --request GET 'http://139.198.166.235:8080/job/acmp-myapp-service/api/json' \
--header 'Authorization: Basic YWRtaW46YWRtaW4='
"displayName": "acmp-myapp-service",
pipeline {
agent any
stages {
stage('Hello') {
steps {
script{
response1= sh returnStdout: true, script:
"""
curl --location \
--request GET \
http://139.198.166.235:8080/job/acmp-myapp-service/api/json \
--header \'Authorization: Basic YWRtaW46YWRtaW4='
"""
response1 = response1 - "\n"
println(response1)
result = readJSON text: "${response1}"
println(result.displayName)
}
}
}
}
}
获取项目构建信息
- 接口:http://127.0.0.1:8080/job/{projectName}/{buildNumber}/api/json
curl --location --request GET 'http://139.198.166.235:8080/job/acmp-myapp-service/30/api/json' \ --header 'Authorization: Basic YWRtaW46YWRtaW4='
获取项目配置
curl --location --request GET 'http://139.198.166.235:8080/job/acmp-myapp-service/config.xml' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Cookie: JSESSIONID.73190a41=node0bg89j02scsymdz0l1n2qv36s15.node0'
创建项目
- 接口:http://127.0.0.1:8080/createItem?name={projectName}
- 参数: --data-binary @config.xml
- 头部:-H "Content-Type:text/xml"
- 方式: POST
先更新到这,后面在更新