我试图在 URL 中传递一个参数,并根据该参数在 javascript 中创建了一个 switch 语句来调用将触发 Jenkins 作业的特定函数。
网址如下所示:http://localhost:8000/user/build-trigger/?job=data1
我的代码如下所示:
$(function(){
init_build_trigger();
})
function init_build_trigger(){
const urlParams = new URLSearchParams(window.location.search) ;
switch (urlParams) {
case "data1":
$.getJson("/model-api/jenkins/build_for_data1/",function(data){
})
break;
case "data2":
$.getJson("/model-api/jenkins/build_for_data2/",function(data){
})
break;
}
console.log(urlParams.get('job')) ;
}
构建函数如下所示:
def build_for_data1(self, request):
url = "jenkins url "
response = requests.get(url)
result = None
if response:
result = "started successfully."
else:
result = "failed. An error has occurred."
return Response(result)
当我访问链接时没有任何反应,作业也没有触发。有人可以解释我缺少什么吗?
慕婉清6462132
相关分类