florentino
V2EX  ›  DevOps

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

  •  
  •   florentino · Jul 17, 2025 · 6770 views
    This topic created in 477 days ago, the information mentioned may be changed or developed.

    事情是这样的,公司使用 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 replies  •  2025-07-21 13:43:37 +08:00
    awker
    awker
    Jul 17, 2025
    1
    系统管理 --> 系统配置 --> Jenkins URL ,看下这个值是否和浏览器的链接 192.168.201.42:18080 一致
    awker
    awker
    Jul 17, 2025
    2
    @awker 如果不一致,就改为一致的
    florentino
    florentino
    OP
    Jul 17, 2025
    3
    @awker #1 这个确认是一致的,初始化的时候会让配置
    patrickyoung
    patrickyoung
    Jul 17, 2025 via Android
    4
    chrome f12 -> network panel -> 找到失败的 request ,码掉 cookies ,贴出来
    florentino
    florentino
    OP
    Jul 17, 2025
    5
    @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%22specified%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
    iyiluo
    Jul 17, 2025
    6
    直接看 jenkins 后台报错日志
    florentino
    florentino
    OP
    Jul 17, 2025
    7
    @iyiluo 没打到后台,直接被浏览器拦截了 , 但是我刚刚在公网机器部署了下, 好像可以, 但是我内网机器为啥不行呢 我再看看, 服气了
    gefranks
    gefranks
    Jul 17, 2025
    8
    开浏览器的隐私模式试过了么?
    lyxxxh2
    lyxxxh2
    Jul 17, 2025❤️1
    9
    我还以为是啥... 就是跨域而已。
    你应该贴报错,head method orign...一个没允许 都可能跨域。
    浏览器肯定有打印。

    至于网上 无脑叫你配置 origin:*,还不如自己耐下心读下文档。
    https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Guides/CORS
    oldManNewThought
    oldManNewThought
    Jul 17, 2025
    10
    jenkins 不要 docker 安装。因为用到宿主机的一些环境,在 docker 里就不好搞了
    florentino
    florentino
    OP
    Jul 17, 2025
    11
    我擦,更炸了, 同样一个镜像,公网服务器部署可以正常使用, 但是内网机器不能正常使用,会出现我上面说的问题,但是问题是 浏览器搞的鬼拦截了
    263
    263
    Jul 17, 2025❤️1
    12
    JenkinsFile 托管到 Git ,用 Pipeline script from SCM
    florentino
    florentino
    OP
    Jul 17, 2025
    13
    我擦 症状好像找到了, 应该是 VPN 的问题, 我同事从内网进行配置,可以正常配置, 我通过 VPN 访问内网进行配置,就被浏览器拦截了, 沃日, 这么神奇吗
    florentino
    florentino
    OP
    Jul 17, 2025
    14
    @263 这样好像不方便, 因为项目比较多, 其他组的项目不方便这样改,还是脚本方便
    weilai99
    weilai99
    Jul 17, 2025
    15
    @florentino 应该是还有防火墙给拦截了
    thealert
    thealert
    Jul 17, 2025❤️1
    16
    复杂请求浏览器先发一个 OPTIONS 请求(预检,称为 preflight ),服务端要对这个请求做回应,而你什么也不写不会发 OPTIONS ,检查网络对 OPTIONS 请求是否有限制等问题
    florentino
    florentino
    OP
    Jul 17, 2025
    17
    @oldManNewThought 这个好解决,配置环境变量就行了
    Belmode
    Belmode
    Jul 17, 2025
    18
    @oldManNewThought #10 完全可以用 docker 好吧,不要误人子弟。只要把 socket 文件用特权模式和工作空间映射暴露出来就行了,用 docker 部署 Jenkins 对它的升级非常友好,出问题可以即刻回滚。
    Belmode
    Belmode
    Jul 17, 2025
    19
    @florentino #13 VPN 的防火墙把 OPTIONS 请求过滤拦截了
    LoNeZ
    LoNeZ
    Jul 18, 2025❤️1
    20
    你这操作有点问题啊. 肯定有日志的 客户端日志 服务端日志 贴日志.
    pckillers
    pckillers
    Jul 18, 2025
    21
    如果真的像楼主所说是有一层防火墙吧楼主的网页操作拦截了,可以考虑把流水线存到 git 上,然后选择“Pipeline script from SCM”从 gir 拉取流水线工作绕开防火墙
    florentino
    florentino
    OP
    Jul 21, 2025
    22
    @pckillers 100% 确定是 VPN 防火墙问题了, 我现在尽量避开在使用 VPN 时配置 Jenkins, 太让人无语了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1715 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 05:30 · PVG 13:30 · LAX 21:30 · JFK 00:30
    ♥ Do have faith in what you're doing.