Jenkins 嵌入到 Iframe

    科技2025-05-29  10

    有时候在搭建一个测试平台的时候, 希望把jenkins嵌入到集成的web portal中, 这时候一般我们会选用Iframe进行嵌入, 代码如下.

    <iframe src="<jenkins url>" width="100%" height="1024" frameborder="0"></iframe>

    但如果单纯的使用这个方法, 会返回一个错误.

    Refused to display '<jenkins url>' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

    在Stack Overflow查了几个方法, 后来发现了一个jenkins 的plugin.

    xframe filter

    下载地址: https://updates.jenkins.io/download/plugins/xframe-filter-plugin/

    下载后, 在jenkins中, upload plugin安装, 安装成功后, 打开manage jenkins页面, 选择Configure System, 找到 XFrame Filter Configuration.

    将 X-Frame-Options Options 改成 ALLOW-FROM uri, 再使用iframe标签加载jenkins, 成功显示.

    Jenkins的默认选项是SAMEORIGIN, 原因如下.

    It’s refused because X-Frame-Options HTTP response header is set to SAMEORIGIN to avoid clickjacking attacks, by ensuring that content cannot embedded into other sites.

    今年由于疫情原因,好久没有更新blog, 今天正好遇到了问题, 就整理进来, 谢谢阅读.

    Processed: 0.010, SQL: 8