jenkins 内置环境变量from jenkins(常用)

Jenkins环境变量探讨 在 Jenkins 的流水线(Pipeline)构建过程中,环境变量扮演着至关重要的角色,它们是流水线与 Jenkins 进行交互的媒介。例如,通过 BUILD_NUMBER 变量,可以获取当前构建任务的编号。这些变量可以分为 Jenkins 内置变量 和 自定义变量。本文将详细讨论这两类变量的使用和管理。 阅读详情

Global Variable Reference

Variables

docker

The docker variable offers convenient access to Docker-related functions from a Pipeline script.

Methods needing a Jenkins agent will implicitly run a node {…} block if you have not wrapped them in one. It is a good idea to enclose a block of steps which should all run on the same node in such a block yourself. (If using a Swarm server, or any other specific Docker server, this probably does not matter, but if you are using the default server on localhost it likely will.)

Some methods return instances of auxiliary classes which serve as holders for an ID and which have their own methods and properties. Methods taking a body return any value returned by the body itself. Some method parameters are optional and are enclosed with []. Reference:

withRegistry(url[, credentialsId]) {…}

Specifies a registry URL such as https://docker.mycorp.com/, plus an optional credentials ID to connect to it.

withServer(uri[, credentialsId]) {…}

Specifies a server URI such as tcp://swarm.mycorp.com:2376, plus an optional credentials ID to connect to it.

withTool(toolName) {…}

Specifies the name of a Docker installation to use, if any are defined in Jenkins global configuration. If unspecified, docker is assumed to be in the $PATH of the Jenkins agent.

image(id)

Creates an Image object with a specified name or ID. See below.

build(image[, args])

Runs docker build to create and tag the specified image from a Dockerfile in the current directory. Additional args may be added, such as '-f Dockerfile.other --pull --build-arg http_proxy=http://192.168.1.1:3128 .'. Like docker build, args must end with the build context. Returns the resulting Image object. Records a FROM fingerprint in the build.

Image.id

The image name with optional tag (mycorp/myapp, mycorp/myapp:latest) or ID (hexadecimal hash).

Image.run([args, command])

Uses docker run to run the image, and returns a Container which you could stop later. Additional args may be added, such as '-p 8080:8080 --memory-swap=-1'. Optional command is equivalent to Docker command specified after the image. Records a run fingerprint in the build.

Image.withRun[(args[, command])] {…}

Like run but stops the container as soon as its body exits, so you do not need a try-finally block.

Image.inside[(args)] {…}

Like withRun this starts a container for the duration of the body, but all external commands (sh) launched by the body run inside the container rather than on the host. These commands run in the same working directory (normally a Jenkins agent workspace), which means that the Docker server must be on localhost.

Image.tag([tagname])

Runs docker tag to record a tag of this image (defaulting to the tag it already has). Will rewrite an existing tag if one exists.

Image.push([tagname])

Pushes an image to the registry after tagging it as with the tag method. For example, you can use image.push 'latest' to publish it as the latest version in its repository.

Image.pull()

Runs docker pull. Not necessary before run, withRun, or inside.

Image.imageName()

The id prefixed as needed with registry information, such as docker.mycorp.com/mycorp/myapp. May be used if running your own Docker commands using sh.

Container.id

Hexadecimal ID of a running container.

Container.stop

Runs docker stop and docker rm to shut down a container and remove its storage.

Container.port(port)

Runs docker port on the container to reveal how the port port is mapped on the host.

pipeline

The pipeline step allows you to define your Pipelines in a more structured way. See the wiki for more information.

env

Environment variables are accessible from Groovy code as env.VARNAME or simply as VARNAME. You can write to such properties as well (only using the env. prefix):

 

env.MYTOOL_VERSION = '1.33'
node {
  sh '/usr/local/mytool-$MYTOOL_VERSION/bin/start'
}

 

These definitions will also be available via the REST API during the build or after its completion, and from upstream Pipeline builds using the build step.

However any variables set this way are global to the Pipeline build. For variables with node-specific content (such as file paths), you should instead use the withEnv step, to bind the variable only within a node block.

A set of environment variables are made available to all Jenkins projects, including Pipelines. The following is a general list of variable names that are available.

BRANCH_NAME

For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).

CHANGE_ID

For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset.

CHANGE_URL

For a multibranch project corresponding to some kind of change request, this will be set to the change URL, if supported; else unset.

CHANGE_TITLE

For a multibranch project corresponding to some kind of change request, this will be set to the title of the change, if supported; else unset.

CHANGE_AUTHOR

For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.

CHANGE_AUTHOR_DISPLAY_NAME

For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.

CHANGE_AUTHOR_EMAIL

For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.

CHANGE_TARGET

For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.

P4_CHANGELIST

P4 Plugin.blurb

P4_CLIENT

P4 Plugin.blurb

P4_PORT

P4 Plugin.blurb

P4_ROOT

P4 Plugin.blurb

P4_USER

P4 Plugin.blurb

P4_TICKET

P4 Plugin.blurb

P4_REVIEW

P4 Plugin.blurb

P4_REVIEW_TYPE

P4 Plugin.blurb

HUDSON_CHANGELOG_FILE

P4 Plugin.blurb

BUILD_NUMBER

The current build number, such as "153"

BUILD_ID

The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds

BUILD_DISPLAY_NAME

The display name of the current build, which is something like "#153" by default.

JOB_NAME

Name of the project of this build, such as "foo" or "foo/bar".

JOB_BASE_NAME

Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".

BUILD_TAG

String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.

EXECUTOR_NUMBER

The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.

NODE_NAME

Name of the agent if the build is on an agent, or "master" if run on master

NODE_LABELS

Whitespace-separated list of labels that the node is assigned.

WORKSPACE

The absolute path of the directory assigned to the build as a workspace.

JENKINS_HOME

The absolute path of the directory assigned on the master node for Jenkins to store data.

JENKINS_URL

Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)

BUILD_URL

Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)

JOB_URL

Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)

SCM-specific variables such as GIT_COMMIT are not automatically defined as environment variables; rather you can use the return value of the checkout step.

As an example of loading variable values from Groovy:

 

mail to: 'devops@acme.com',
    subject: "Job '${JOB_NAME}' (${BUILD_NUMBER}) is waiting for input",
    body: "Please go to ${BUILD_URL} and verify the build"

 

params

Exposes all parameters defined in the build as a read-only map with variously typed values. Example:

if (params.BOOLEAN_PARAM_NAME) {doSomething()}

or to supply a nontrivial default value:

if (params.get('BOOLEAN_PARAM_NAME', true)) {doSomething()}

Note for multibranch (Jenkinsfile) usage: the properties step allows you to define job properties, but these take effect when the step is run, whereas build parameter definitions are generally consulted before the build begins. As a convenience, any parameters currently defined in the job which have default values will also be listed in this map. That allows you to write, for example:

properties([parameters([string(name: 'BRANCH', defaultValue: 'master')])])
git url: '…', branch: params.BRANCH

and be assured that the master branch will be checked out even in the initial build of a branch project, or if the previous build did not specify parameters or used a different parameter name.

currentBuild

The currentBuild variable, which is of type RunWrapper, may be used to refer to the currently running build. It has the following readable properties:

 

number

build number (integer)

result

typically SUCCESS, UNSTABLE, or FAILURE (may be null for an ongoing build)

currentResult

typically SUCCESS, UNSTABLE, or FAILURE. Will never be null.

resultIsBetterOrEqualTo(String)

Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is better than or equal to the provided result.

resultIsWorseOrEqualTo(String)

Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is worse than or equal to the provided result.

displayName

normally #123 but sometimes set to, e.g., an SCM commit identifier

description

additional information about the build

id

normally number as a string

timeInMillis

time since the epoch when the build was scheduled

startTimeInMillis

time since the epoch when the build started running

duration

duration of the build in milliseconds

durationString

a human-readable representation of the build duration

previousBuild

another similar object, or null

nextBuild

similarly

absoluteUrl

URL of build index page

buildVariables

for a non-Pipeline downstream build, offers access to a map of defined build variables; for a Pipeline downstream build, any variables set globally on env

changeSets

a list of changesets coming from distinct SCM checkouts; each has a kind and is a list of commits; each commit has a commitId, timestamp, msg, author, and affectedFiles each of which has an editType and path; the value will not generally be Serializable so you may only access it inside a method marked @NonCPS

rawBuild

a hudson.model.Run with further APIs, only for trusted libraries or administrator-approved scripts outside the sandbox; the value will not be Serializable so you may only access it inside a method marked @NonCPS

Additionally, for this build only (but not for other builds), the following properties are writable:

 

  • result
  • displayName
  • description
  • keepLog

scm

Represents the SCM configuration in a multibranch project build. Use checkout scm to check out sources matching Jenkinsfile. 
You may also use this in a standalone project configured with Pipeline from SCM, though in that case the checkout will just be of the latest revision in the branch, possibly newer than the revision from which the Pipeline was loaded.

Artifactory

Jfrog Artifactory Pipeline DSL. 
Full documentation is available here: the plugin's Wiki page.

manager

Executes a groovy script in the Jenkins JVM. Typically, the script checks some conditions and changes accordingly the build result, puts badges next to the build in the build history and/or displays information on the build summary page. 
The groovy script can use the variable manager, which provides access to the following objects and methods:

 

 

 

 

  • hudson - the current Hudson instance (javadoc).
  • build - the current build (javadoc).
  • listener - the build listener (javadoc).
  • contains(file, regexp) - returns true if the given file contains a line matching regexp.
  • logContains(regexp) - returns true if the build log file contains a line matching regexp.
  • getMatcher(file, regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the given file.
  • getLogMatcher(regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the build log file.
  • getResult() - returns the current build result.
  • addShortText(text) - puts a badge with a short text, using the default format.
  • addShortText(text, color, background, border, borderColor) - puts a badge with a short text, using the specified format.
  • addBadge(icon, text) - puts a badge with the given icon and text.
  • addBadge(icon, text, link) - puts a badge with the given icon and text linking to link.
  • addInfoBadge(text) - puts a badge with  info icon and the given text.
  • addWarningBadge(text) - puts a badge with  warning icon and the given text.
  • addErrorBadge(text) - puts a badge with  error icon and the given text.
  • createSummary(icon) - creates an entry in the build summary page and returns a summary object corresponding to this entry. You can append text to the summary object by calling its appendText methods:
    • - appendText(text, escapeHtml)
    • - appendText(text, escapeHtml, bold, italic, color)
  • buildUnstable() - sets the build result to UNSTABLE.
  • buildFailure() - sets the build result to FAILURE.
  • buildSuccess() - sets the build result to SUCCESS.
  • buildAborted() - sets the build result to ABORTED.
  • buildNotBuilt() - sets the build result to NOT_BUILT.

Example:

    if(manager.logContains(".*uses or overrides a deprecated API.*")) {
      manager.addWarningBadge("Thou shalt not use deprecated methods.")
      manager.createSummary("warning.gif").appendText("<h1>You have been warned!</h1>", false, false, false, "red")
      manager.buildUnstable()
    }
  • The script also has two ways of accessing environment variables. The first one is a quick and dirty one time access if you needed only one variable. You could do that with manager.envVars["variable"].
  • If you wanted to get a hashmap of the entire environment, use def environment = manager.getEnvVars() and simply use environment as a hash map.
  • See Jenkins Wiki for more information.
jenkins——环境变量、节点配置以及节点环境变量的使用 全局环境变量入口 Dashboard -> 系统管理(Manage Jenkins) -> 系统配置(Configure System)-> 全局属性。 阅读详情

相关推荐

40-Jenkins-环境变量的使用

Jenkins-环境变量的使用

小白的博客 2785

Jenkins - 访问 Jenkins 自定义参数变量,处理变量值中含有空格

Jenkins job 中会自定义一些变量,这些变量将被不同的插件访问。工作中有遇到一个坑,就是变量值中含有空格时,当变量做为参数调用 Python 函数时,空格后面的内容会被截断,本文将解决这个问题。.........

wumingxiaoyao的博客 1829

从KVM虚拟化到Openstack云化架构综述

目录 摘要 OpenStack的虚拟化技术 OpenStack架构介绍 Nova Swift KeyStone Neutron Glance Cinder Ceilometer Heat 摘要 这两年的工作中,接触到公有云和私有云的项目还不少。起初对于Openstack的了解,仅停留在其几大组件的交互上,如Nova、Neutron、Glance等,以及对各大云厂商功能点上...

liyunpeng229的博客 2059

python将jenkins获取的时间转换为正常的年月日显示

from datetime import datetime #将jenkinspipeline中的currentBuild.startTimeInMillis转换为日常使用的时间格式: #a=int(currentBuild.startTimeInMillis) a=1611737708290 b=datetime.fromtimestamp(a/1000) c=datetime.fromtimestamp(a/1000).strftime('%Y-%m-%d %H:%M:%S') print(b) pri

qq_46020608的博客 1129

肌电信号检测与处理:从传感器原理到Arduino实战应用

肌电信号(EMG)是肌肉收缩时产生的生物电信号,其检测技术是人机交互、康复医疗和运动科学等领域的重要基础。通过高输入阻抗仪表放大器和带通滤波器,传感器能够有效抑制工频干扰等噪声,将微弱的毫伏级信号放大并转换为微控制器可读取的模拟电压。在Arduino等嵌入式平台上,结合移动平均滤波等信号处理算法,可以从原始数据中提取出稳定的肌肉活动特征,实现对外部设备的实时控制。这一技术为仿生假肢、体感交互和可穿戴健康设备等应用场景提供了核心支持,而Grove - EMG检测器模块则通过即插即用的设计,显著降低了硬件集成和

weixin_26742753的博客 286

Python开发者必看:5分钟搞定Gemini API的3种调用方式(含代码示例)

本文为Python开发者详细介绍了三种高效调用Gemini API的核心方式:基础同步调用、流式调用和聊天模式,并涵盖多模态应用等高级特性。通过清晰的代码示例和实战场景分析,帮助开发者快速掌握Gemini API的集成与优化,提升AI应用开发效率。

g8f9d0s1a2的博客 1134

让Jenkins 的环境变量不在困惑

前言 Jenkins, DevOps 技术栈的核心之一,CI/CD 离不开编写 Pipeline 脚本,上手 Jenkins ,简单查一下文档,你就应该不会被 agent,stages,step 这类关键词弄懵,也能很快构建出 pipeline 的骨架 但是当向骨架中填充内容的时候,尤其如何利用环境变量(系统内置 | 自定义),多数人都会变得比较混乱,浪费很多时间,本文就帮助大家快速通关环境变量 准备 如果你想一边阅读本文,一边实践,但是没有 Jenkins 服务可用,又想快速尝试,可以应用 D

Enweitech Software Works 1024

百度文心大模型ERNIE全面解析

文章摘要:本文汇总了多个Python自然语言处理(NLP)工具库的应用实例,涵盖百度文心大模型ERNIE、Hugging Face Transformers、StanfordNLP、SymSpell等主流框架。内容涉及文本预处理、情感分析、命名实体识别、机器翻译、文本纠错等典型NLP任务,并包含ERNIE-Lite、BART、T5等模型的调用示例。各工具库的特色功能包括:ERNIE的知识增强技术、Transformers的多任务统一接口、SymSpell的高效拼写纠正等。文章还提供了知识图谱构建、Rasa对

keny-大成的博客 2556

Jenkins 环境变量的作用范围及设置与获取,包括在Sharedlibraries与pipelin之间的传递

首先要注意的是单引号,双引号,3单引号,3双引号的使用区别。 用def 在某个stage内定义的变量,仅在这个stage内有效。 要想定义的变量在每个stage内都有效,就在pipeline首部定义全局变量。可以在任意stage修改这个全局变量,使用时需要使用双引号或者3双引号才行。使用单引号或者3单引号是不行的。示例见文末。 1 Jenkins内置的环境变量 Jenkins环境变量是通过env变量公开的全局变量,可以在Jenkins文件中的任何位置使用。存储在env变量中的任何值都存储为字符串类型。.

云原生,DevOps,Kubernetes 9777

ChatGPT设置密钥后Codex免手机验证:配置顺序与身份凭证复用机制

API Key 是一种用于身份识别的凭证,其核心原理是通过预配置的密钥替代交互式登录流程。在开发工具中,密钥认证优先级通常高于会话认证,当本地存在有效密钥时,工具会直接复用该凭证,从而减少重复验证环节。这种机制的技术价值在于提升开发效率与配置一致性,尤其适用于多设备切换、CI/CD 流水线及编程辅助工具等场景。以 Codex 为例,在 ChatGPT 界面提前配置 API 密钥后,Codex 启动时可读取持久化存储的密钥,避免触发手机号验证,实现身份凭证的跨入口复用。

weixin_33940469的博客 565

交换机四种光互联技术:OIO、OBO、NPO与CPO

在过去几十年里,数据中心交换机主要依赖电信号通过铜线进行数据传输。然而,随着数据传输速率从100Gbps向400Gbps、800Gbps甚至1.6Tbps迈进,传统电互联(Electrical Input & Output, EIO)面临三大瓶颈:信号衰减、功耗激增和空间限制。例如,高速信号在长距离铜线传输中会产生严重的信号失真,迫使设计者加入数字信号处理器(DSP)来补偿信号衰减,这进一步推高了功耗和成本。此外,传统可插拔光模块的体积较大,限制了端口密度,难以满足现代数据中心对高带宽密度的需求。

网络技术联盟站 3222

Jenkins全局环境变量

Jenkins Set Environment Variables   When a Jenkins job executes, it sets some environment variables that you may use in your shell script, batch command, Ant script or Maven POM #1. The following ta...

qq625281334的专栏 2110

读懂 SAP S/4HANA 里的 SAP Fiori 架构:前端服务器、搜索链路、传统应用接入与内容组织全景解析

摘要:SAP Fiori架构并非简单的系统连接图,而是明确区分界面层与业务数据层的三层分工体系:用户交互层(浏览器与Fiori launchpad)、前端技术层(SAPUI5运行环境)和业务数据层(SAP S/4HANA后端)。这种分离实现了生命周期解耦,前端专注于统一体验治理,后端处理核心业务逻辑。值得注意的是,SAP Fiori front-end server本质仍是ABAP系统,负责UI技术组件运行。虽然SAP S/4HANA推荐嵌入式部署,但独立部署在多系统场景中仍有价值。典型Fiori应用通过O

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 185

Jenkins内置环境变量的使用

一、查看Jenkins有哪些环境变量 1、新建任意一个job 2、增加构建步骤:Execute shell 或 Execute Windows batch command 3、点击输入框下方的“可用环境变量” 4、可以看到有如下变量供使用: 变量名 解释 BUILD_NUMBER The current build number, such as "153" B...

quliuwuyiz的博客 2117

知识追踪实战:lstm+ Multi-head Attention注意力机制的学生做题成绩预测实战

知识追踪实战:lstm+ Multi-head Attention注意力机制的学生做题成绩预测实战

2228

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

jenkins内置环境变量大全

Jenkins 提供了许多内置环境变量,帮助你在 Jenkins 作业中获取关键信息。

完颜振江 2519

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jenkins内置环境变量

jenkins内置环境变量 echo "BUILD_NUMBER" :: $BUILD_NUMBER echo "BUILD_ID" :: $BUILD_ID echo "BUILD_DISPLAY_NAME" :: $BUILD_DISPLAY_NAME echo "JOB_NAME" :: $JOB_NAME echo "JOB_BASE_NAME" :: $JOB_BASE_NAME echo "BUILD_TAG" :: $BUILD_TAG echo "EXECUTOR_NUMBER" :: $E

wejack的专栏 618

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Jenkins常用的内置环境变量

可以直接在job配置里查看 唯一标识一次build:${BUILD_NUMBER} BUILD_ID,基本上等同于BUILD_NUMBER,但是是字符串,例如20111115160621; job的名字:JOB_NAME job的当前工作目录,到具体job目录下:${WORKSPACE},如: + echo ---WORKSPACE--- ---WORKSPACE--- + ech...

wan_zaiyunduan的博客 1117

Jenkins - 内置变量访问

最近一直困惑于 Jenkins 的一个环境变量 CAUSE, 在邮件插件中调用 ${CAUSE} 是可行的,但是在其它地方(执行 Shell 或 Python 脚本时),确只能得到 None 值。原来 Jenkins 内置变量是分为两类,一类只供邮件配置使用的配置变量,一类是全局环境变量,下面一起了解一下这些变量。...

wumingxiaoyao的博客 3236

jenkins内置提供的全局变量

jenkins内置提供的全局变量。

1852

jenkins 内置环境变量

jenkins 内置环境变量 介绍几个经常用到的变量 BUILD_ID 当前构建的 ID,与 Jenkins 版本 1.597+ 中创建的构建号 BUILD_NUMBER 是完全相同的。 BUILD_NUMBER 当前构建号,比如 “18”。 BUILD_TAG 字符串 jenkins–$ {JOB_NAME}-${BUILD_NUMBER}。可以放到源代码、jar 等文件中便于识别。 BUILD_URL 可以定位此次构建结果的 URL(比如 http://buildserve

飘然渡沧海的博客 2038

10分钟搞定让你困惑的 Jenkins 环境变量

前言Jenkins, DevOps 技术栈的核心之一,CI/CD 离不开编写 Pipeline 脚本,上手 Jenkins ,简单查一下文档,你就应该不会被 agent,stages,s...

程序猿DD 2039

Jenkins:常用环境变量

echo"BUILD_DISPLAY_NAME=${BUILD_DISPLAY_NAME}" echo"BUILD_ID=${BUILD_ID}" echo"BUILD_NUMBER=${BUILD_NUMBER}" echo"BUILD_TAG=${BUILD_TAG}" ...

Weeds的博客 1943
上一篇: docker下载私有仓库镜像失败:Error response from daemon: Get $ip:5000/v2/: http: server gave HTTP response to HT
下一篇: jenkins pipeline执行中错误: java.io.NotSerializableException: hudson.model.User
liurizhou
博客等级 码龄11年 1946粉丝 88原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值