V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
florentino
V2EX  ›  DevOps

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

  •  
  •   florentino · 16 天前 · 2579 次点击

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

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