一个 Jenkins 技术问题,要被搞疯了 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
florentino
V2EX    DevOps

一个 Jenkins 技术问题,要被搞疯了

  •  
  •   florentino 86 天前 3283 次点击
    这是一个创建于 86 天前的主题,其中的信息可能已经有所发展或是发生改。

    事情是这样的,公司使用 Jenkins 来进行服务的编译及部署的,但是我最近在修改流水线的配置的时候,发现提交报错,而且问题是由于浏览器拦截造成的,本来以为是我版本造成的,结果部署了一个最新版也是这样的

    具体细节如下:

    测试通过 docker 进行(普通 war 启动症状一样),启动脚本如下:

    docker run --rm --name jenkins -p 18080:8080 jenkins/jenkins:jdk21 

    启动后,默认安装推荐插件,进入系统后随便新建一个 job,此时,脚本内不填入任何内容,可以提交成功 https://imgur.com/nL4JXea

    但是如果我填入一个内容,点击应用就会报错,被浏览器拦截,并且控制台竟然报跨域 https://imgur.com/An6lnSS https://imgur.com/undefined

    在网上搜了 2 天没找到解决方法,要崩溃了 (ps, 忽略截图中的版本,我是从最新版往下试的)

    22 条回复    2025-07-21 13:43:37 +08:00
    awker
        1
    awker  
       86 天前
    系统管理 --> 系统配置 --> Jenkins URL ,看下这个值是否和浏览器的链接 192.168.201.42:18080 一致
    awker
        2
    awker  
       86 天前
    @awker 如果不一致,就改为一致的
    florentino
        3
    florentino  
    OP
       86 天前
    @awker #1 这个确认是一致的,初始化的时候会让配置
    patrickyoung
        4
    patrickyoung  
       86 天前 via Android
    chrome f12 -> network panel -> 找到失败的 request ,码掉 cookies ,贴出来
    florentino
        5
    florentino  
    OP
       86 天前
    @patrickyoung
    请求网址: http://192.168.201.42:18080/job/test/configSubmit
    引荐来源网址政策 same-origin
    请求体:
    enable=true&description=&stapler-class-bag=true&_.projectUrlStr=&_.displayName=&_.daysToKeepStr=&_.numToKeepStr=&_.artifactDaysToKeepStr=&_.artifactNumToKeepStr=&stapler-class=hudson.tasks.LogRotator&%24class=hudson.tasks.LogRotator&hint=MAX_SURVIVABILITY&stapler-class-bag=true&_.upstreamProjects=&ReverseBuildTrigger.threshold=SUCCESS&_.spec=&_.scmpoll_spec=&quiet_period=5&authToken=&_.displayNameOrNull=&oldScript=&_.script=pipeline+%7B%0D%0A++++agent+any%0D%0A%0D%0A++++stages+%7B%0D%0A++++++++stage%28%27Hello%27%29+%7B%0D%0A++++++++++++steps+%7B%0D%0A++++++++++++++++echo+%27Hello+World%27%0D%0A++++++++++++%7D%0D%0A++++++++%7D%0D%0A++++%7D%0D%0A%7D%0D%0A&_.sandbox=on&stapler-class=org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition&%24class=org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition&stapler-class=org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition&%24class=org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition&core%3Aapply=true&Jenkins-Crumb=f8b745cc6b9dca90b5e911a951101213d4a9c03740fa8855479e3ea297c05ddc&json=%7B%22enable%22%3Atrue%2C%22description%22%3A%22%22%2C%22properties%22%3A%7B%22stapler-class-bag%22%3A%22true%22%2C%22com-coravy-hudson-plugins-github-GithubProjectProperty%22%3A%7B%7D%2C%22hudson-model-ParametersDefinitionProperty%22%3A%7B%22specified%22%3Afalse%7D%2C%22org-jenkinsci-plugins-workflow-job-properties-DisableConcurrentBuildsJobProperty%22%3A%7B%22specifed%22%3Afalse%2C%22abortPrevious%22%3Afalse%7D%2C%22jenkins-model-BuildDiscarderProperty%22%3A%7B%22specified%22%3Afalse%2C%22%22%3A%220%22%2C%22strategy%22%3A%7B%22daysToKeepStr%22%3A%22%22%2C%22numToKeepStr%22%3A%22%22%2C%22artifactDaysToKeepStr%22%3A%22%22%2C%22artifactNumToKeepStr%22%3A%22%22%2C%22stapler-class%22%3A%22hudson.tasks.LogRotator%22%2C%22%24class%22%3A%22hudson.tasks.LogRotator%22%7D%7D%2C%22org-jenkinsci-plugins-workflow-job-properties-DisableResumeJobProperty%22%3A%7B%22specified%22%3Afalse%7D%2C%22org-jenkinsci-plugins-workflow-job-properties-DurabilityHintJobProperty%22%3A%7B%22specified%22%3Afalse%2C%22hint%22%3A%22MAX_SURVIVABILITY%22%7D%2C%22org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty%22%3A%7B%22triggers%22%3A%7B%22stapler-class-bag%22%3A%22true%22%7D%7D%7D%2C%22hasCustomQuietPeriod%22%3Afalse%2C%22quiet_period%22%3A%225%22%2C%22displayNameOrNull%22%3A%22%22%2C%22%22%3A%220%22%2C%22definition%22%3A%7B%22oldScript%22%3A%22%22%2C%22script%22%3A%22pipeline+%7B%5Cn++++agent+any%5Cn%5Cn++++stages+%7B%5Cn++++++++stage%28%27Hello%27%29+%7B%5Cn++++++++++++steps+%7B%5Cn++++++++++++++++echo+%27Hello+World%27%5Cn++++++++++++%7D%5Cn++++++++%7D%5Cn++++%7D%5Cn%7D%5Cn%22%2C%22%22%3A%5B%22try+sample+Pipeline...%22%2C%22hello%22%2C%22%5Cn%5Cn%22%5D%2C%22sandbox%22%3Atrue%2C%22stapler-class%22%3A%22org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition%22%2C%22%24class%22%3A%22org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition%22%7D%2C%22Submit%22%3A%22%22%2C%22core%3Aapply%22%3A%22true%22%2C%22Jenkins-Crumb%22%3A%22f8b745cc6b9dca90b5e911a951101213d4a9c03740fa8855479e3ea297c05ddc%22%7D

    请求截图:
    https://imgur.com/undefined
    https://imgur.com/n1HOXLE
    https://imgur.com/gtfKIiH
    iyiluo
        6
    iyiluo  
       86 天前
    直接看 jenkins 后台报错日志
    florentino
        7
    florentino  
    OP
       86 天前
    @iyiluo 没打到后台,直接被浏览器拦截了 , 但是我刚刚在公网机器部署了下, 好像可以, 但是我内网机器为啥不行呢 我再看看, 服气了
    gefranks
        8
    gefranks  
       86 天前
    开浏览器的隐私模式试过了么?
    lyxxxh2
        9
    lyxxxh2  
       86 天前   1
    我还以为是啥... 就是跨域而已。
    你应该贴报错,head method orign...一个没允许 都可能跨域。
    浏览器肯定有打印。

    至于网上 无脑叫你配置 origin:*,还不如自己耐下心读下文档。
    https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Guides/CORS
    oldManNewThought
        10
    oldManNewThought  
       86 天前
    jenkins 不要 docker 安装。因为用到宿主机的一些环境,在 docker 里就不好搞了
    florentino
        11
    florentino  
    OP
       86 天前
    我擦,更炸了, 同样一个镜像,公网服务器部署可以正常使用, 但是内网机器不能正常使用,会出现我上面说的问题,但是问题是 浏览器搞的鬼拦截了
    263
        12
    263  
       86 天前   1
    JenkinsFile 托管到 Git ,用 Pipeline script from SCM
    florentino
        13
    florentino  
    OP
       86 天前
    我擦 症状好像找到了, 应该是 VPN 的问题, 我同事从内网进行配置,可以正常配置, 我通过 VPN 访问内网进行配置,就被浏览器拦截了, 沃日, 这么神奇吗
    florentino
        14
    florentino  
    OP
       86 天前
    @263 这样好像不方便, 因为项目比较多, 其他组的项目不方便这样改,还是脚本方便
    weilai99
        15
    weilai99  
       86 天前
    @florentino 应该是还有防火墙给拦截了
    thealert
        16
    thealert  
       86 天前   1
    复杂请求浏览器先发一个 OPTIONS 请求(预检,称为 preflight ),服务端要对这个请求做回应,而你什么也不写不会发 OPTIONS ,检查网络对 OPTIONS 请求是否有限制等问题
    florentino
        17
    florentino  
    OP
       86 天前
    @oldManNewThought 这个好解决,配置环境变量就行了
    Belmode
        18
    Belmode  
       86 天前
    @oldManNewThought #10 完全可以用 docker 好吧,不要误人子弟。只要把 socket 文件用特权模式和工作空间映射暴露出来就行了,用 docker 部署 Jenkins 对它的升级非常友好,出问题可以即刻回滚。
    Belmode
        19
    Belmode  
       86 天前
    @florentino #13 VPN 的防火墙把 OPTIONS 请求过滤拦截了
    LoNeZ
        20
    LoNeZ  
       85 天前   1
    你这操作有点问题啊. 肯定有日志的 客户端日志 服务端日志 贴日志.
    pckillers
        21
    pckillers  
       85 天前
    如果真的像楼主所说是有一层防火墙吧楼主的网页操作拦截了,可以考虑把流水线存到 git 上,然后选择“Pipeline script from SCM”从 gir 拉取流水线工作绕开防火墙
    florentino
        22
    florentino  
    OP
       82 天前
    @pckillers 100% 确定是 VPN 防火墙问题了, 我现在尽量避开在使用 VPN 时配置 Jenkins, 太让人无语了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     841 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 22ms UTC 20:44 PVG 04:44 LAX 13:44 JFK 16:44
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86